1 #include<iostream> 2 #include<string> 3 #include<sstream> 4 using namespace std; 5 void check(string a){ 6 int cnt_index=0,cnt_int=0; 7 for(unsigned j=0;j<a.length();j++){ 8 if(a[j]>=‘0‘&&a[j]<=‘9‘){ 9 cnt_int*=10; 10 cnt_int+=a[j]-‘0‘; 11 } 12 else{ 13 if(cnt_int==0){ 14 cnt_int=1; 15 } 16 cnt_index=j; 17 for(int i=0;i<cnt_int;i++){ 18 j=cnt_index; 19 if(a[j]!=‘(‘&&a[j]!=‘)‘){ 20 cout<<a[j]; 21 } 22 else{ 23 j++; 24 string c;int nleft=1,nright=0; 25 while(nleft!=nright){ 26 if(a[j]==‘(‘){ 27 nleft++; 28 } 29 if(a[j]==‘)‘){ 30 nright++; 31 } 32 if(nleft!=nright){//char string的转换 33 stringstream stream; 34 stream << a[j]; 35 c += stream.str(); 36 j++; 37 } 38 39 } 40 check(c); 41 } 42 } 43 cnt_int=0; 44 } 45 } 46 } 47 int main(){ 48 int n; 49 cin>>n; 50 string *a=new string[n]; 51 for(int i=0;i<n;i++){ 52 cin>>a[i]; 53 } 54 for(int i=0;i<n;i++){ 55 check(a[i]); 56 cout<<endl; 57 } 58 return 0; 59 }
时间: 2024-10-28 13:59:42