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. 玩转iOS开发 - Runloop 具体解释

    Runloop 具体解释

  2. Linux 0.11中write实现

    看了一下Linux 0.11版本号write的实现,首先它在标准头文件unistd.h中有定义 int write(int fildes, const char * buf, off_t count) ...

  3. PHP中用下标符号[]去读取字符串的逻辑

    PHP中 [(下标)] 符号不仅能够应用于数组和对象,还能够应用于字符串,假设不注意非常easy出错. 比方获取一个网络接口,正常情况下会返回一个数组结构的json,经过解析之后结果为: array( ...

  4. 去除iframe滚动条

    主页面的IFRAME中添加:scrolling="yes" 子页面程序代码: 让竖条消失: <body style='overflow:scroll;overflow-x:a ...

  5. nyoj--814--又见拦截导弹(动态规划+贪心)

    又见拦截导弹 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 大家对拦截导弹那个题目应该比较熟悉了,我再叙述一下题意:某国为了防御敌国的导弹袭击,新研制出来一种导弹拦截系 ...

  6. Codeforces 676E The Last Fight Between Human and AI 规律

    链接 Codeforces 676E The Last Fight Between Human and AI 题意 给一个多项式,有些系数不确定.人和机器轮流填系数,系数可以是任何数,问是否能使得最后 ...

  7. 51nod 2020 排序相减(暴力解法)

    题目: 代码: #include <bits\stdc++.h> using namespace std; int trim(int x){ ]; ;i < ; i++){ a[i] ...

  8. 【原创】VMWare克隆或复制Linux虚拟机后无法上网的解决

    如果选择桥接,需要设置网卡通过哪个物理网卡桥接,桥接代表当前虚拟机通过本机的网卡直接连到网络中,本机网卡作为一个交换机直连.因此需要确定使用哪个网卡桥接,一般在单网卡的时候选择自动即可,多网卡时需要指 ...

  9. 监控RMAN操作进度的脚本

    REM ------------------------------- REM Script to monitor rman backup/restore operations REM To run ...

  10. css实现步骤条

    实现效果 html <ul class="steps"> <li class="active">申请完成</li> < ...