Http://livearchive.onlinejudge.org/index.php? Option = com_onlinejudge & Itemid = 8 & page = show_problem & problem = 2967
First, we need to find the deepest depth, and then use parity to identify whether to perform a crossover or complement operation. An odd number indicates an operation, and an even number indicates a supplementary operation.
Note that the global variable I is used to solve the problem of repeated calculation. It is worth noting.
#include<iostream>#include<string.h>#include<stdio.h>#include<algorithm>using namespace std;char s[40000];char s2[3]="()";int i;int solve(int k,int id){ int ans=id; for(i=++k;;i++) { if(s[i]==')')return ans; else if(s[i]=='T') { if(id)ans&=1; else ans|=1; } else if(s[i]=='F') { if(id)ans&=0; else ans|=0; } else if(s[i]=='(') { if(id)ans&=solve(i,id^1); else ans|=solve(i,id^1); } }}int main(){ int test=1; while(cin>>s) { int ans=0; int temp=0; if(!strcmp(s,s2))break; int len=strlen(s); for(int j=0;j<len;j++) { if(s[j]=='(')temp++; else if(s[j]==')') ans=max(ans,temp),temp--; } printf("%d. ",test++); i=0; temp=solve(0,ans%2); if(temp==0) cout<<"false"<<endl; else cout<<"true"<<endl; } //system("pause"); return 0;}