AcWing 3244. Markdown
原题链接
中等
作者:
Jin_YZZ
,
2021-04-08 16:29:31
,
所有人可见
,
阅读 392
#include <bits/stdc++.h>
using namespace std;
void qiangdiao(string& s);//多个函数时,要提前申明!!!!
void cont();
void qiangdiao(string& s){
int x,y;
while(x=s.find('_'), x!=-1){
s.replace(x,1,"<em>");
y=s.find('_');
s.replace(y,1,"</em>");
}
//找 超链接
int x1;
while(x1=s.find('['),x1!=-1){
int i,j;
string text,link,out;
for(i=x1+1;s[i]!=']';i++){
text+=s[i];
}
for(j=i+2;s[j]!=')';j++){
link+=s[j];
}
out="<a href=\""+link+"\">"+text+"</a>";
s.replace(x1,j-x1+1,out);
}
}
void cont()
{
string s,s1;
while (getline(cin, s))
{
if(s.size()==0)break;
qiangdiao(s);
cout << endl<< s;
}
return;
}
int main()
{
string s;
while (getline(cin, s))
{
if (s.size() == 0)
continue;
qiangdiao(s);//先处理强调
if (s[0] == '#')//处理标题
{
int i;
for (i = 0;; i++)
{
if (s[i] == '#')
continue;
break;
}
printf("<h%d>", i);
int j;
for (j = i; j < s.size(); j++)
{
if (s[j] == ' ')
continue;
break;
}
for(;j<s.size();j++)
cout<<s[j];
cont();
printf("</h%d>\n", i);
}
else if(s[0]=='*'){//处理列表
cout<<"<ul>"<<endl;
int j;
qiangdiao(s);
do{
cout<<"<li>";
qiangdiao(s);
for(j=1;j<s.size();j++){
if(s[j]==' ') continue;
break;
}
for(;j<s.size();j++)
cout<<s[j];
cout<<"</li>"<<endl;
}while(getline(cin,s)&&(s.size()!=0));
cout<<"</ul>"<<endl;
}
else//处理段落
{
cout << "<p>" << s;
cont();
cout << "</p>" << endl;
}
}
system("pause");
return 0;
}