电子竞技,菜是原罪,只有90分。。。。。 死活找不到错在哪儿
#include <bits/stdc++.h>
using namespace std;
void print(string sentence){
for(int i = 0; i < sentence.size(); i++){
if(sentence[i] == '['){
string temp = sentence.substr(i+1,sentence.find(']')-i-1);
int t = sentence.find('(',i);
i = sentence.find(')',t);
cout << "<a href=\"";
print(sentence.substr(t+1,i-t-1));
cout << "\">";
print(temp);
cout<< "</a>";
}
else if(sentence[i] == '_'){
int t = sentence.find('_',i+1);
cout << "<em>";
print(sentence.substr(i+1,t-i-1));
cout << "</em>" ;
i = t;
}
else if(sentence[i] == ';')cout << "\n";
else cout << sentence[i];
}
}
void format(string &sentence){
int h = 0;
bool table = false;
if(sentence[0] == '*') table = true;
while(sentence[h] == '#') h++;
if(h == 0 && table == false){
cout << "<p>";
int t = 0;
while(sentence[t]==' ') t++;
print(sentence.substr(t));
cout << "</p>" << endl;
}
else if(h > 0){
printf("<h%d>",h);
int t = h;
while(sentence[t] == ' ') t++;
print(sentence.substr(t));
printf("</h%d>\n",h);
}
else{
int t = 0;
cout << "<ul>\n";
while(sentence[t] == '*' && t < sentence.size()){
cout << "<li>";
int tt = t + 1;
while(sentence[tt] == ' ')tt++;
if(sentence.find('*',t+1) != string::npos){
print(sentence.substr(tt,sentence.find('*',t+1) - 1 - tt));
t = sentence.find('*',t+1);
}
else {
print(sentence.substr(tt,sentence.find(';',t+1) - tt));
t = sentence.find(';',t+1);
}
cout << "</li>\n";
}
cout << "</ul>\n";
}
}
void change_into_html(string &html){
string sentence;
for(int i = 0; i < html.size(); i++){
int n = 0;
while(html[i] == ';'){
n++;
i++;
}
if(n >= 2 || i == html.size()){
if(sentence.size() > 0)
format(sentence);
sentence = "";
i--;
}
else if(n==1)sentence += html[--i];
else sentence += html[i];
}
}
int main(){
//freopen("1.txt","r",stdin);
string s;
string html;
while(getline(cin,s))
html +=s + ";";
change_into_html(html);
}
活找不出来错在哪儿