noip2017 DAY1- T2

模拟的题:https://www.luogu.org/problemnew/show/P3952

别忘了栈!!!

调试时出的问题:

1.忘了删freopen(回坑的疏忽)

2.很多地方是数字字符串结合输入。。。判断误认为数字为一位数

3.栈没有彻底清空

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

using namespace std;

struct node
{
	char i;
	int n;//n的指数 
};

int main()
{
	int a,b,i,t,line,tr[27],j,k,err,rans,ans,zs,max1,begin1,end1;
	char s[500],s1[5],s2[5],begin[50],end[50];
	stack  st;
	stack  st1;
	node n1,n2;
	
	freopen("a.txt","r",stdin);
	scanf("%d",&t);//程序数
	
	for (i=0;iend1))
					zs=-1;
				else
					zs=0;
				
				if (tr[s2[0]-'a']==0)		//判重 
				{
					tr[s2[0]-'a']=1;
					n1.i=s2[0];		n1.n=zs;
					st.push(n1);	st1.push(0);
				}
				else
					err=1;			
			}
			else if (s1[0]=='E')
			{
				if (err==1)
					continue;
					
				if (st.empty())		//E!=F
				{
					err=1;
					continue;
				}
				n2=st.top();	max1=st1.top();
				st.pop();		st1.pop();
				tr[n2.i-'a']=0;
					
				if (n2.n==-1)			
					continue;
				
				ans=max(st1.top(),max1+n2.n);
				st1.pop();
				st1.push(ans);
			}
		}
		if (err==1)
		{
			printf("ERR\n");
			while (!st.empty())
				st.pop();
			while (!st1.empty())
				st1.pop();
//			printf("%d\n",st1.size());
			continue;
		}
		if (!st.empty())
		{
			printf("ERR\n");
			while (!st.empty())
				st.pop();
			while (!st1.empty())
				st1.pop();
			continue;
		}
		if (st1.top()==rans)
			printf("Yes\n");
		else
		{
//			printf("%d ",st1.top());
			printf("No\n");
		}
		st1.pop();
	}
	
	return 0;
}

 

你可能感兴趣的:(noip2017 DAY1- T2)