这题本来我用模拟的方法过了,后来看了题解,觉得递归实在是写得很好,我就照着写了一个,但是9号点挂了,不知道为啥。
我的代码:
#include <bits/stdc++.h>
#define f(i,a,b) for(int i=a;i<=b;i++)
#define g(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
string read() {
int n;
string s="",s1;
char c=getchar();
while(!(c=='\r'||c=='\n')) {
if(c=='[') {
cin>>n;
s1=read();
while(n--) s+=s1;
}else if(c==']') return s;
else s+=c;
c=getchar();
}
}
int main(){
cout<<read();
return 0;
}
只是题解写得是:
while (cin>>c)
因为这句我看不懂,我就改成了:
while(!(c=='\r'||c=='\n')) {
感觉也没问题啊,求大佬指点下。