1813: good string

Time Limit: 1 Sec  Memory Limit: 128 MB

Submit: 93  Solved: 15



SubmitStatusWeb
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<stdio.h>
#include<string.h>
#include<algorithm>
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;i<len;i++)
{
if(str[i]=='s')
continue;
else if(str[i]=='p')
continue;
else if(str[i]=='y')
continue;
else if(str[i]=='!')
{
if(str[i+1]==')'||i==len-1)
{
flog=false;
break;
}
}
else if(str[i]=='(')
{
l++;
if(i==len-1)
{
flog=false;
break;
}
if(str[i+1]==')')
{
flog=false;
break;
}
}
else if(str[i]==')')
{
r++;
if(i==0||r>l)
{
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;
}

zzulioj--1813--good string(模拟)的更多相关文章

  1. B. Obtaining the String(模拟)

    比较水的模拟 思路:就是模拟题意 注意:把数组开大点,开始wa了几次就是这个原因 #include<iostream> #include<string> #include< ...

  2. STL string 模拟

    下面的代码来自c++ primer plus第5版第12章,书中代码写的非常好: // string1.h -- fixed and augmented string class definition ...

  3. Codeforces-B-Game with string(模拟栈)

    Two people are playing a game with a string ss, consisting of lowercase latin letters. On a player's ...

  4. HDOJ 5414 CRB and String 模拟

    CRB and String Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) T ...

  5. [agc007f] Shik and Copying String 模拟神题

    Description ​ "全"在十分愉快打工,第0天,给了他一个仅有小写字母构成的长度为N的字符串S0,在之后的第i天里,"全"的工作是将Si−1复制一份到 ...

  6. Codeforce-CodeCraft-20 (Div. 2)-B. String Modification (找规律+模拟)

    Vasya has a string s of length n. He decides to make the following modification to the string: Pick ...

  7. 【翻译】为什么Java中的String不可变

    笔主前言: 众所周知,String是Java的JDK中最重要的基础类之一,在笔主心中的地位已经等同于int.boolean等基础数据类型,是超越了一般Object引用类型的高端大气上档次的存在. 但是 ...

  8. 牛客多校训练第八场G.Gemstones(栈模拟)

    题目传送门 题意: 输入一段字符串,字符串中连续的三个相同的字符可以消去,消去后剩下的左右两段字符串拼接,求最多可消去次数. 输入:ATCCCTTG   输出:2 ATCCCTTG(消去CCC)——& ...

  9. 北京师范大学第十五届ACM决赛-重现赛C Captcha Cracker (字符串模拟)

    链接:https://ac.nowcoder.com/acm/contest/3/C 来源:牛客网 Captcha Cracker 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 26 ...

随机推荐

  1. HDU 4324 Contest 3

    直接DFS即可 #include <iostream> #include <string.h> #include <algorithm> #include < ...

  2. POJ 2480

    可以容易得知,F=sum(p*phi(n/p)).思路就断在这里了... 看过别人的,才知道如下: 由于gcd(i,n*m)=gcd(i,m)*gcd(i,n),所以gcd为积性函数.而积性函数之和为 ...

  3. 怎样更好的深入学习andorid

    把主要的控件  基本布局 基本组件  数据存储都熟悉一边,在看网络的时候,有点不知道怎么搞了.由于一直用c开发,但接触socket也不多,这两天把java的socket编程熟悉了下.找了非常多书,可是 ...

  4. Sping框架中的注解详解

    传统的Spring做法是使用.xml文件来对bean进行注入或者是配置aop.事物,这么做有两个缺点:1.如果所有的内容都配置在.xml文件中,那么.xml文件将会十分庞大:如果按需求分开.xml文件 ...

  5. Codeforces 13C Sequence dp

    题目链接:http://codeforces.com/problemset/problem/13/C 题意: 给定n长的序列 每次操作能够给每一个数++或-- 问最少须要几步操作使得序列变为非递减序列 ...

  6. poj 2488 A Knight&#39;s Journey(dfs+字典序路径输出)

    转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj.org/problem? id=2488 ----- ...

  7. bzoj3732: Network(最小生成树+LCA)

    3732: Network 题目:传送门 题解: 第一眼就看到最大边最小,直接一波最小生成树. 一开始还担心会错,问了一波肉大佬,任意两点在最小生成树上的路径最大边一定是最小的. 那么事情就变得简单起 ...

  8. php设计模式之工厂方法模式

    php设计模式之工厂方法模式 工厂方法模式 工厂方法模式(Factory Method Pattern)又称为工厂模式,也叫虚拟构造器(Virtual Constructor)模式或者多态工厂(Pol ...

  9. hdoj--1010--Tempter of the Bone(搜索+奇偶剪枝)

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  10. python+caffe训练自己的图片数据流程

    1. 准备自己的图片数据 选用部分的Caltech数据库作为训练和测试样本.Caltech是加州理工学院的图像数据库,包含Caltech101和Caltech256两个数据集.该数据集是由Fei-Fe ...