作者:小SASA的天空 | 来源:互联网 | 2023-08-27 19:05
这道题不存在递归结构
比如区块之间的相互嵌套 还有"[ [] ]" 链接的相互嵌套, 所以直接处理就好了
还可以
1 #include
2 using namespace std;
3 string trans (string str) {
4 string tmp; int i=0;
5 while (i<str.size()) {
6 bool flag=0; string txt,link;
7 while (i‘[‘) tmp+=str[i++];
8 if (str[i]==‘[‘) { flag=1; i++;}
9 if (flag) {
10 while (str[i]!=‘]‘) txt+=str[i++];
11 i+=2;
12 while (str[i]!=‘)‘) link+=str[i++];
13 i++;
14 tmp+=""+link+"\">"+txt+"";
15 }
16 }
17 str=tmp; tmp=""; i=0;
18 while (i<str.size()) {
19 bool flag=0; string txt;
20 while (i‘_‘) tmp+=str[i++];
21 if (str[i]==‘_‘) {flag=1; i++;}
22 if (flag) {
23 while (str[i]!=‘_‘) txt+=str[i++];
24 i++;
25 tmp+=""+txt+"";
26 }
27 }
28 return tmp;
29 }
30 void trs2(string str) {
31 int i=1; for (;str[i]==‘ ‘;i++);
32 cout<<""<"\n";
33 }
34 int main ()
35 {
36 string str;
37 //freopen("test.txt","r",stdin);
38 while (getline(cin,str)) {
39 if (str[0]==‘#‘) {
40 int i=0,x=0;
41 for (;str[i]==‘#‘;i++) x++;
42 for (;str[i]==‘ ‘;i++);
43 cout<<""<">"<""<">\n";
44 }
45 else if (str[0]==‘*‘) {
46 cout<<"";
47 trs2(str);
48 while (getline(cin,str)&&str.size()!=0)
49 trs2(str);
50 cout<<"\n";
51 }
52 else if (str.size()!=0) {
53 cout<<""<<trans(str);
54 while (getline(cin,str)&&str.size()!=0)
55 cout<<"\n"<<trans(str);
56 cout<<"
\n
";
57 }
58 }
59 return 0;
60 }