标签:
直接在字符串上搜索,注意逗号的处理
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 #include<queue> 7 #include<map> 8 using namespace std; 9 #define MOD 1000000007 10 #define pb(a) push_back(a) 11 const int INF=0x3f3f3f3f; 12 const double eps=1e-5; 13 typedef long long ll; 14 #define cl(a) memset(a,0,sizeof(a)) 15 #define ts printf("*****\n"); 16 const int MAXN=30010; 17 int n,m,tt,cnt; 18 int pos=0,num=1,len; 19 vector<int> vc; 20 vector<string> ans; 21 char s[10000010]; 22 void dfs() 23 { 24 if(pos>=len) return; 25 string ss; 26 while(s[pos]>=‘a‘&&s[pos]<=‘z‘) 27 { 28 ss.push_back(s[pos]); 29 pos++; 30 } 31 ans.push_back(ss); 32 int now=num++; 33 vc.push_back(now); 34 if(s[pos]==‘(‘) 35 { 36 pos++; 37 dfs(); 38 vc.push_back(now); 39 while(s[pos]==‘,‘) 40 { 41 pos++; 42 dfs(); 43 vc.push_back(now); 44 } 45 pos++; 46 } 47 else return; 48 } 49 int main() 50 { 51 int i,j,k; 52 #ifndef ONLINE_JUDGE 53 freopen("1.in","r",stdin); 54 #endif 55 scanf("%d",&tt); 56 while(tt--) 57 { 58 ans.clear(); 59 vc.clear(); 60 pos=0; 61 num=1; 62 scanf("%s",s); 63 len=strlen(s); 64 65 dfs(); 66 printf("%d\n",num-1); 67 for(int i=0;i<ans.size();i++){ 68 printf("%s\n",ans[i].c_str()); 69 } 70 for(int i=0;i<vc.size()-1;i++){ 71 printf("%d %d\n",vc[i],vc[i+1]); 72 } 73 printf("\n"); 74 } 75 }
标签:
原文地址:http://www.cnblogs.com/cnblogs321114287/p/4711241.html