题目大意:略
傻了吧唧的我wa了好几次
我的模拟功底真的不咋地
linux下用gets会报错,我用的fgets
1 #include <string> 2 #include "stdio.h" 3 #include <cstring> 4 #include <iostream> 5 #include <algorithm> 6 #define ll long long 7 #define N 1010 8 #define rint register int 9 #define ll long long 10 #define il inline 11 #define idx(x) (x-'a'+1) 12 #define idg(x) (x-'0') 13 using namespace std; 14 //re 15 int T,n,cnt,j; 16 int use[30]; 17 char str[110][20]; 18 inline bool isdig(char c) 19 {return ('0'<=c&&c<='9')?1:0;} 20 int dfs() 21 { 22 int ans=0,now=j,val=0,cal=0; 23 if(str[j][0]=='E') return -1; 24 if(str[j][0]=='F') 25 { 26 if(use[idx(str[j][2])]) 27 return -1; 28 use[idx(str[j][2])]=1; 29 while(str[j+1][0]=='F') 30 { 31 j++,cal=dfs(); 32 if(cal==-1) return -1; 33 ans=max(ans,cal); 34 } 35 int k=4; 36 while(isdig(str[now][k])) 37 val=val*10+idg(str[now][k]),k++; 38 k++; 39 if(str[now][4]=='n'){ 40 if(str[now][6]!='n') ans=0; 41 }else if(!isdig(str[now][k])){ 42 ans++; 43 }else{ 44 int w=0; 45 while(isdig(str[now][k])) 46 w=w*10+idg(str[now][k]),k++; 47 if(val>w) ans=0; 48 } 49 } 50 use[idx(str[now][2])]=0; 51 j++; 52 if(str[j][0]!='E') return -1; 53 else return ans; 54 } 55 56 int main() 57 { 58 //freopen("complexity6.in","r",stdin); 59 scanf("%d",&T); 60 for(int t=1;t<=T;t++) 61 { 62 int q=0; 63 scanf("%d",&n); 64 memset(str,0,sizeof(str)); 65 memset(use,0,sizeof(use)); 66 scanf("%s ",str[0]); 67 for(int i=1;i<=n;i++) 68 fgets(str[i],20,stdin); 69 int ret=0,ans=0;j=1; 70 for(;j<=n;j++){ 71 ans=dfs(); 72 if(ans==-1){ret=-1;printf("ERR ");break;} 73 else {ret=max(ret,ans);} 74 } 75 if(ret==-1) continue; 76 int k=0,flag=0; 77 while(1){ 78 if(str[0][k]=='n') flag=1; 79 if(!isdig(str[0][k])) 80 {k++;continue;} 81 while(isdig(str[0][k])) 82 q=q*10+idg(str[0][k]),k++; 83 break; 84 } 85 if(flag==0) q=0; 86 if(ret==q) printf("Yes "); 87 else printf("No "); 88 } 89 return 0; 90 }