评测记录
60分:2、5、6、10WA,其它的AC
求找错!
#include<bits/stdc++.h>
using namespace std;
bool p=false;
string ans="";
string change1(string x)
{
if(x=="[h1]")return "# ";
else if(x=="[h2]")return "## ";
else if(x=="[i]")return "*";
else if(x=="[b]")return "__";
else if(x=="[url]")return "[";
else if(x=="[img]")return "![";
else if(x=="[quote]")
{
p=true;
return "";
}
return x;
}
string change2(string x,string t)
{
if(x=="[h1]")return " #";
else if(x=="[h2]")return " ##";
else if(x=="[i]")return "*";
else if(x=="[b]")return "__";
else if(x=="[url]")return "]("+t+")";
else if(x=="[img]")return "]("+t+")";
return x;
}
void work(string n)
{
string t,x;
if(n.find("=")!=string::npos)t=n.substr(n.find("=")+1,n.size()-n.find("=")-2),n.erase(n.find("="),n.size()-n.find("=")-1);
ans+=change1(n);
if(p)
{
char u=getchar();
string v="";
bool fff=false;
while(u!=EOF)
{
if(u=='[')fff=true;
if(fff)v+=u;
if(u==']')
{
fff=false;
if(v=="[/quote]")break;
v="";
}
t+=u,u=getchar();
}
if(u==EOF)cout<<"Unclosed Mark",exit(0);
t=t.substr(0,t.size()-7);
while(t[t.size()-1]=='\n')t.erase(t.size()-1,1);
while(t[0]=='\n')t.erase(0,1);
t="\n"+t;
for(int i=0;i<t.size();i++)
if(t[i]=='\n'&&i!=t.size()-1)ans+="\n> ";
else ans+=t[i];
ans+="\n",p=false;
return;
}
char c=getchar();
while(c!=EOF)
{
if(c=='[')
{
getline(cin,x,']'),x="["+x+"]";
if(x[1]=='/')
{
x.erase(1,1),ans+=change2(x,t);
if(x==n)return;
else cout<<"Match Error",exit(0);
}
else work(x);
}
else ans+=c;
c=getchar();
}
cout<<"Unclosed Mark",exit(0);
}
int main()
{
string x;
while(1)
{
x="";
char c=getchar();
bool fff=false;
while(c!=EOF)
{
if(c=='[')fff=true;
if(fff)x+=c;
else ans+=c;
if(c==']')
{
fff=false;
break;
}
c=getchar();
}
if(c==EOF)break;
if(x[1]=='/')cout<<"Match Error",exit(0);
else work(x);
}
cout<<ans;
return 0;
}