记录编号 | 107794 | 评测结果 | AAAAA | ||
---|---|---|---|---|---|
题目名称 | [Tyvj Aug11] 括号匹配 | 最终得分 | 100 | ||
用户昵称 | 是否通过 | 通过 | |||
代码语言 | C++ | 运行时间 | 1.026 s | ||
提交时间 | 2014-06-29 20:29:41 | 内存使用 | 95.68 MiB | ||
- #include<fstream>
- #include<string>
- #include<cstring>
- using namespace std;
- ifstream fin("kakko.in");
- ofstream fout("kakko.out");
- char Stack[20000001];
- int T[20000001];
- int ZZ=0,N;
- void push(char a)
- {
- ZZ++;
- Stack[ZZ]=a;
- }
- void pop()
- {
- ZZ--;
- }
- bool flag=0;
- int main()
- {
- string A;
- fin>>N;
- int i,j,L,k;
- int MAX=0;
- for(i=1;i<=N;i++)
- {
- fin>>A;
- L=A.length();
- for(j=0;j<=L-1;j++)
- {
- if(A[j]=='('||A[j]=='['||A[j]=='{'||A[j]=='<')
- {
- push(A[j]);
- if(ZZ>MAX)
- MAX=ZZ;
- if(ZZ==MAX)
- T[MAX]++;
- }
- if(A[j]==')')
- {
- if(Stack[ZZ]!='('&&Stack[ZZ]!='L')
- {
- fout<<"FALSE"<<endl;
- flag=1;
- break;
- }
- else
- pop();
- }
- if(A[j]=='>')
- {
- if(Stack[ZZ]!='<'&&Stack[ZZ]!='L')
- {
- fout<<"FALSE"<<endl;
- flag=1;
- break;
- }
- else
- pop();
- }
- if(A[j]==']')
- {
- if(Stack[ZZ]!='['&&Stack[ZZ]!='L')
- {
- fout<<"FALSE"<<endl;
- flag=1;
- break;
- }
- else
- pop();
- }
- if(A[j]=='}')
- {
- if(Stack[ZZ]!='{'&&Stack[ZZ]!='L')
- {
- fout<<"FALSE"<<endl;
- flag=1;
- break;
- }
- else
- pop();
- }
- if(A[j]=='/')
- {
- push('L');if(ZZ>MAX) {MAX=ZZ;T[MAX]++;}
- }
- if(A[j]=='#')
- {for(k=1;k<=2;k++) push('L');if(ZZ>MAX) {MAX=ZZ;T[MAX]++;}}
- if(A[j]=='@')
- {for(k=1;k<=4;k++) push('L');if(ZZ>MAX) {MAX=ZZ;T[MAX]++;}}
- if(A[j]=='?')
- {for(k=1;k<=8;k++) push('L');if(ZZ>MAX) {MAX=ZZ;T[MAX]++;}}
- if(A[j]=='\\')
- {pop();}
- if(A[j]=='*')
- {for(k=1;k<=2;k++)pop();}
- if(A[j]=='&')
- {for(k=1;k<=4;k++) pop();}
- if(A[j]=='!')
- {for(k=1;k<=8;k++) pop();}
- }
- if(flag==0)
- {
- if(ZZ==0)
- fout<<"TRUE"<<' '<<MAX<<' '<<T[MAX]<<endl;
- else
- fout<<"FALSE"<<endl;
- }
- ZZ=0;//栈清空
- flag=0;
- MAX=0;
- memset(T,0,sizeof(T));
- }
- return 0;
- }