zzulioj--1813--good string(模拟)

1813: good string

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 93  Solved: 15

Submit Status Web Board

Description

给定一个字符串,判断它是否是good string。

good string定义为:

① 字符s是good string,字符p是good string,字符y也是good string

② P和Q都是good string,则PQ是good string

③ P是good string,则(P)是good string

④ P是good string,则!P是good string

⑤ P和Q都是good string,则P|Q和P&Q是good string

Input

输入包含多组数据。每组数据为一行字符串,长度不超过100。

Output

对于每组数据,如果P是good string则输出"P is a good string",否则输出"P is not a good string"。

Sample Input

!spy!(s|p!y))sp|y

Sample Output

!spy is a good string!(s|p!y) is a good string)sp|y is not a good string
我去,上次太着急,没粘代码就走了- -||

#include
#include
#include
using namespace std;
char str[10010];
int main()
{
	while(scanf("%s",str)!=EOF)
	{
		int len=strlen(str);
		int l=0,r=0;
		bool flog=true;
		for(int i=0;il)
				{
					flog=false;
					break;
				}
				if(str[i-1]!='p'&&str[i-1]!='s'&&str[i-1]!='y'&&str[i-1]!=')')
				{
					flog=false;
					break;
				}
			}
			else if(str[i]=='&')
			{
				if(i==0)
				{
					flog=false;
					break;
				}
				if(str[i+1]=='('||str[i+1]=='y'||str[i+1]=='s'||str[i+1]=='p'||str[i+1]=='!');
				else 
				{
					flog=false;
					break;
				}
				if(str[i-1]=='s'||str[i-1]==')'||str[i-1]=='y'||str[i-1]=='p');
				else
				{
					flog=false;
					break;
				}
			}
			else if(str[i]=='|')
			{
				if(i==0)
				{
					flog=false;
					break;
				}
				if(str[i+1]=='('||str[i+1]=='y'||str[i+1]=='s'||str[i+1]=='p'||str[i+1]=='!');
				else 
				{
					flog=false;
					break;
				}
				if(str[i-1]=='s'||str[i-1]==')'||str[i-1]=='y'||str[i-1]=='p');
				else
				{
					flog=false;
					break;
				}
			}
			else
			{
				flog=false;
				break;
			}
		}
		if(r!=l)
		{
			flog=false;
		}
		printf("%s",str);
		if(flog)
		printf(" is a good string\n");
		else
		printf(" is not a good string\n");
		memset(str,'\0',sizeof(str));
	}
	return 0;
}


转载于:https://www.cnblogs.com/playboy307/p/5273625.html

你可能感兴趣的:(zzulioj--1813--good string(模拟))