100分
#include<bits/stdc++.h>
using namespace std;
vector<string> vt[105];//一个vector:一个区块
void fun(string &s){//处理行内
int i,j;
for(i=0;i<s.size();i++){
int ii,jj;
string temp,href;
while(i<s.size()&&s[i]!='[')
i++;
ii=i;
j=i+1;
while(j<s.size()&&s[j]!=']')
j++;
if(j<s.size()){
temp=s.substr(i+1,j-i-1);
i=j+2;
j=i+1;
while(j<s.size()&&s[j]!=')')
j++;
jj=j+1;
href=s.substr(i,j-i);
//s.replace(ii,jj-ii,"<a href=("+href+")>"+temp+"</a>");
s.replace(ii,jj-ii,"<a href=\""+href+"\">"+temp+"</a>");
i=ii;
}
}
for(i=0;i<s.size();i++){
while(i<s.size()&&s[i]!='_')
i++;
j=i+1;
while(j<s.size()&&s[j]!='_')
j++;
if(j<s.size()){
string temp=s.substr(i+1,j-i-1);
temp="<em>"+temp+"</em>";
s.replace(i,j-i+1,temp);
}
}
}
int main() {
string line[105];
int i=0,j,k,n;
while(getline(cin,line[i]))
i++;
n=i;//有n行
for(i=0,k=0;i<n;){
while(i<n&&line[i].size()==0)
i++;
for(j=i;j<n&&line[j].size()!=0;j++)
vt[k].push_back(line[j]);
k++;
i=j+1;
}//有k个区块
for(i=0;i<k;i++){
if(vt[i][0][0]=='#'){//标题区块 1行
int c=0;//级数
while(vt[i][0][0]=='#'||vt[i][0][0]==' '){
if(vt[i][0][0]=='#')
c++;
vt[i][0].erase(vt[i][0].begin());
}
string temp1,temp2,t1,t2,t3,d;//这里不知道为什么不能直接用:temp1="<h"+'0'+c+">"; 很奇怪啊
t1="<h";
t2="</h";
t3=">";
d='0'+c;
temp1=t1+d+t3;
temp2=t2+d+t3;
fun(vt[i][0]);
vt[i][0].insert(0,temp1);
vt[i][0].insert(vt[i][0].size(),temp2);
}
else if(vt[i][0][0]=='*'){//列表区块
for(j=0;j<vt[i].size();j++){//第i区第j个字符串
while(vt[i][j][0]=='*'||vt[i][j][0]==' ')
vt[i][j].erase(vt[i][j].begin());
fun(vt[i][j]);
vt[i][j].insert(0,"<li>");
vt[i][j].insert(vt[i][j].size(),"</li>");
}
vt[i].insert(vt[i].begin(),"<ul>");
vt[i].push_back("</ul>");
}
else{//段落区块
for(j=0;j<vt[i].size();j++)
fun(vt[i][j]);
vt[i][0].insert(0,"<p>");
vt[i][vt[i].size()-1]+="</p>";
}
}
for(i=0;i<k;i++){
for(j=0;j<vt[i].size();j++)
cout<<vt[i][j]<<endl;
}
return 0;
}