标签:格式 class UI amp 相互 语法错误 插入 技术分享 clear
题意:
#include<bits/stdc++.h> using namespace std; string s; int deal1(int id, string& s2, string& ans); int deal2(int id, string& s2, string& ans); int deal1(int id, string& s2, string& ans){ ans += "<em>"; int i; for(i = id + 1; s2[i] != ‘_‘; ++i){ if(s2[i] == ‘[‘){ i = deal2(i, s2, ans); } else{ ans += s2[i]; } } ans += "</em>"; return i; } int deal2(int id, string& s2, string& ans){ ans += "<a href=\""; int j = id; while(s2[j] != ‘(‘) ++j; int i; for(i = j + 1; s2[i] != ‘)‘; ++i){ if(s2[i] == ‘_‘){ i = deal1(i, s2, ans); } else{ ans += s2[i]; } } ans += "\">"; int k = id; while(s2[k] != ‘[‘) ++k; for(int ii = k + 1; s2[ii] != ‘]‘; ++ii){ if(s2[ii] == ‘_‘){ ii = deal1(ii, s2, ans); } else{ ans += s2[ii]; } } ans += "</a>"; return i; } void deal(string s2){ int len2 = s2.size(); int cnt = 0; string ans; for(int i = 0; i < len2; ++i){ if(s2[i] == ‘_‘){ i = deal1(i, s2, ans); } else if(s2[i] == ‘[‘){ i = deal2(i, s2, ans); } else{ ans += s2[i]; } } printf("%s", ans.c_str()); } vector<string> v; int main(){ while(getline(cin, s)){ if(s[0] == ‘#‘){ stringstream ss(s); string s1; ss >> s1; int len1 = s1.size(); printf("<h%d>", len1); int id = len1; while(s[id] == ‘ ‘) ++id; int len = s.size(); string s2 = s.substr(id, len - id); deal(s2); printf("</h%d>\n", len1); } else if(s[0] == ‘*‘){ v.clear(); stringstream ss(s); string s1; ss >> s1; int len1 = s1.size(); int id = len1; while(s[id] == ‘ ‘) ++id; int len = s.size(); string s2 = s.substr(id, len - id); v.push_back(s2); while(getline(cin, s)){ if(s == "") break; stringstream sss(s); sss >> s1; len1 = s1.size(); id = len1; while(s[id] == ‘ ‘) ++id; len = s.size(); s2 = s.substr(id, len - id); v.push_back(s2); } printf("<ul>\n"); int l = v.size(); for(int i = 0; i < l; ++i){ printf("<li>"); deal(v[i]); printf("</li>\n"); } printf("</ul>\n"); } else if(s == "") continue; else{ printf("<p>"); deal(s); bool ok = false; while(getline(cin, s)){ if(s == ""){ ok = true; printf("</p>\n"); break; } else{ printf("\n"); deal(s); } } if(!ok){ printf("</p>\n"); } } } return 0; }
标签:格式 class UI amp 相互 语法错误 插入 技术分享 clear
原文地址:http://www.cnblogs.com/tyty-Somnuspoppy/p/7623733.html