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. Error: Password file read access must be restricted: /etc/cassandra/jmxremote.password

    在配置JMX远程访问的时候,设置jmxremote.password文件权限,修改该文件时添加写权限,chmod +w jmxremote.password ,放开角色信息那俩行的注释,保存,再使用c ...

  2. 百度 谷歌 Twitter,这么多短链接服务(Short Url)究竟哪家强?

    一.短链接是什么 url=HPqdQ5VR3vA39x7ZWoWyNzwWnsDhTbh66BTpdzsJLroBDzFRm4JV-G818Zc027uZrwe7zxtxnD4H2FUahftpUK& ...

  3. Linux - Redmine使用方式 | SVN提交代码

    Redmine使用方式 | SVN提交代码 本文地址:http://blog.csdn.net/caroline_wendy RbTools 1. 安装: svn co https://dev.cxx ...

  4. android 推断手机是否支持前置摄像头

    话不多说 直接上代码, @SuppressLint("NewApi") public static boolean isSupportFrontCamera() { if (!ha ...

  5. log4j.xml打印日志信息(2)

    log4j.xml文件 <? xml version="1.0" encoding="UTF-8"?> <!DOCTYPE log4j:con ...

  6. sql两个字段相加减,第三个字段没有值的原因.

    错误的写法:(in_story_num-out_story_num) as story_num 正确的写法:(nvl(in_story_num,0)-nvl(out_story_num,0)) as ...

  7. apiCloud中实现头部与内容分离与操作规范,App头部header固定,头部与内容分离

    官方案例 1.头部拆分成一个页面比如news-text <!doctype html> <html> <head> <meta charset="u ...

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

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

  9. 配置NTP集群时间同步(二)

    [root@hadoop1 bin]# rpm -qa|grep ntp 没有的话用yum -y install ntp安装(要记着每台机器上都要安装) [root@hadoop1 bin]# vi ...

  10. http请求常出现的状态码

    服务器返回的 响应报文 中第一行为状态行,包含了状态码以及原因短语,用来告知客户端请求的结果. 状态码 类别 原因短语 1XX Informational(信息性状态码) 接收的请求正在处理 2XX ...