CCF第三题,一道相对简单的字符串模拟题
每次先读取一行line,先把“强调”和“超链接”处理完毕,然后分3种情况处理:
1.若line[0]为‘#’,说明是标题
2.若line[0]为“*”,说明是列表,反复读取并处理直到空行
3.说明是普通的段落,反复读取并处理直到空行
#include
#include
#include
#include
using namespace std;
void deal_emphasis(string& a)
{
int cnt = 0;
size_t p;
while((p = a.find("_")) != string::npos)
{
++cnt;
if(cnt&1) a.replace(p,1,"");
else a.replace(p,1,"");
}
}
bool deal_url(string& a)
{
int s1,s2,c1,c2;
s1=s2=c1=c2=-1;
for(size_t i=0; i" + test + "";
a.replace(s1,c2-s1+1,res);
return 1;
}
return 0;
}
void erase_blank(string& a)
{
for(size_t i=0; i>t1;
getline(ss,t2);
cout<<"";
erase_blank(t2);
cout<\n";
//Heading
}
else if(tmp[0] == '*')
{
tmp[0] = ' ';
erase_blank(tmp);
cout<<"\n"<<"- "<
\n";
while(getline(cin, tmp) && !tmp.empty())
{
deal_emphasis(tmp);
while(deal_url(tmp));
tmp[0] = ' ';
erase_blank(tmp);
cout<<"- "<
\n";
}
cout<<"
\n";
}
else
{
cout<<""<\n";
}
}
return 0;
}
/*
# heading
## sub-heading
paragraphs are separated
by a blank line.
test _italic_.
bullet list:
* apple
* orange
* pear
[link](http://www.baidu.com).
_[link](http://www.baidu.com)_
*/