记录编号 45594 评测结果 AAAAA
题目名称 [Tyvj Aug11] 括号匹配 最终得分 100
用户昵称 GravatarMakazeu 是否通过 通过
代码语言 C++ 运行时间 0.255 s
提交时间 2012-10-24 17:47:20 内存使用 0.31 MiB
显示代码纯文本
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <stack>
#include <iostream>
#include <string>
#include <algorithm>
#define loop(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
char c,s; int L,T,t;
string str;
stack<int> sta;
int fuka,num,now;

inline void solve()
{
	L=str.length();
	for(int i=0;i<L;i++)
	{
		c=str[i];
		if(c==')'){if(sta.empty()) goto endgame; t=sta.top();sta.pop();if(t!=1 && t!=5) goto endgame; now--;continue;}
		if(c==']'){if(sta.empty()) goto endgame; t=sta.top();sta.pop();if(t!=2 && t!=5) goto endgame; now--;continue;}
		if(c=='}'){if(sta.empty()) goto endgame; t=sta.top();sta.pop();if(t!=3 && t!=5) goto endgame; now--;continue;}
		if(c=='>'){if(sta.empty()) goto endgame; t=sta.top();sta.pop();if(t!=4 && t!=5) goto endgame; now--;continue;}
		if(c=='\\'){loop(k,1,1) {if(sta.empty()) goto endgame;  sta.pop(); now--;}continue;}
		if(c=='*'){loop(k,1,2) {if(sta.empty()) goto endgame;  sta.pop(); now--;}continue;}
		if(c=='&'){loop(k,1,4) {if(sta.empty()) goto endgame;  sta.pop(); now--;}continue;}
		if(c=='!'){loop(k,1,8) {if(sta.empty()) goto endgame;  sta.pop(); now--;}continue;}
		
		
		if(c=='('){sta.push(1);now++; if(now==fuka) num++;  if(now>fuka) fuka=now,num=1;continue;}
		if(c=='['){sta.push(2);now++; if(now==fuka) num++;  if(now>fuka) fuka=now,num=1;continue;}
		if(c=='{'){sta.push(3);now++; if(now==fuka) num++;  if(now>fuka) fuka=now,num=1;continue;}
		if(c=='<'){sta.push(4);now++; if(now==fuka) num++;  if(now>fuka) fuka=now,num=1;continue;}
		if(c=='/'){sta.push(5);now++; if(now==fuka) num++;  if(now>fuka) fuka=now,num=1;continue;}
		if(c=='#'){loop(k,1,2) sta.push(5);now+=2; if(now==fuka) num++;  if(now>fuka) fuka=now,num=1;continue;}
		if(c=='@'){loop(k,1,4) sta.push(5);now+=4; if(now==fuka) num++;  if(now>fuka) fuka=now,num=1;continue;}
		if(c=='?'){loop(k,1,8) sta.push(5);now+=8; if(now==fuka) num++;  if(now>fuka) fuka=now,num=1;continue;}
	}
	if(sta.empty()) {printf("TRUE %d %d\n",fuka,num); return;}
	endgame: printf("FALSE\n");return;
}

int main()
{
	freopen("kakko.in","r",stdin);
	freopen("kakko.out","w",stdout);
	std::ios::sync_with_stdio(0);
	cin>>T;  getline(cin,str); 
	for(int i=1;i<=T;i++)
	{
		fuka=0,num=0,now=0;
		while(sta.size()) sta.pop();
		str.clear();
		getline(cin,str);
		solve();
	}
	return 0;
}