poj 1126 Simply Syntax

#include <iostream>
#include
<string>
using namespace std;
int main()
{
string data;
int i,top,list[260];
bool tag;
while(cin>>data)
{
top
=data.size()-1;
tag
=1;
for(i=0;i<=top;i++)
{
if(data[i]=='N')
list[i]
=1;
else if(data[i]=='C'||data[i]=='D'||data[i]=='E'||data[i]=='I')
list[i]
=2;
else if(data[i]>='p'&&data[i]<='z')
list[i]
=-1;
else
{
tag
=0;break;
}
}
if(tag==0)
printf(
"NO\n");
else
{
int sum=0;
while(top>=0)
{
sum
+=list[top];
if(sum>0)
break;
if(list[top]>0)
sum
--;
top
--;
}
if(sum==-1)
printf(
"YES\n");
else
printf(
"NO\n");
}
}
return 0;
}

  

posted on 2011-07-20 22:34  sysu_mjc  阅读(137)  评论(0编辑  收藏  举报

导航