zzulioj--1813--good string(模拟)
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
Sample Output
#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(模拟)的更多相关文章
- B. Obtaining the String(模拟)
比较水的模拟 思路:就是模拟题意 注意:把数组开大点,开始wa了几次就是这个原因 #include<iostream> #include<string> #include< ...
- STL string 模拟
下面的代码来自c++ primer plus第5版第12章,书中代码写的非常好: // string1.h -- fixed and augmented string class definition ...
- Codeforces-B-Game with string(模拟栈)
Two people are playing a game with a string ss, consisting of lowercase latin letters. On a player's ...
- HDOJ 5414 CRB and String 模拟
CRB and String Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) T ...
- [agc007f] Shik and Copying String 模拟神题
Description "全"在十分愉快打工,第0天,给了他一个仅有小写字母构成的长度为N的字符串S0,在之后的第i天里,"全"的工作是将Si−1复制一份到 ...
- 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 ...
- 【翻译】为什么Java中的String不可变
笔主前言: 众所周知,String是Java的JDK中最重要的基础类之一,在笔主心中的地位已经等同于int.boolean等基础数据类型,是超越了一般Object引用类型的高端大气上档次的存在. 但是 ...
- 牛客多校训练第八场G.Gemstones(栈模拟)
题目传送门 题意: 输入一段字符串,字符串中连续的三个相同的字符可以消去,消去后剩下的左右两段字符串拼接,求最多可消去次数. 输入:ATCCCTTG 输出:2 ATCCCTTG(消去CCC)——& ...
- 北京师范大学第十五届ACM决赛-重现赛C Captcha Cracker (字符串模拟)
链接:https://ac.nowcoder.com/acm/contest/3/C 来源:牛客网 Captcha Cracker 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 26 ...
随机推荐
- nginx編譯
openssl源码安装后,编译nginx-1.9.7或者openresty找不到OpenSSL的解决办法 http://blog.csdn.net/zhiyuan_2007/article/detai ...
- LeetCode104_MaximumDepthofBinaryTree Java题解
题目: Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the ...
- Unsupported major.minor version 51.0问题的解决
在java编程的过程中,当用myeclipse软件打开别人写的代码时,遇到Unsupported major.minor version 51.0此类问题,实在是令人痛苦不堪.弄了整整一晚才搞清楚,我 ...
- poj1363——Rails
Description There is a famous railway station in PopPush City. Country there is incredibly hilly. Th ...
- bzoj2663: [Beijing wc2012]灵魂宝石(二分+匈牙利)
2663: [Beijing wc2012]灵魂宝石 题目:传送门 题解: 又是一道卡精度的题目. 很容易就可以看出单调性啊,如果R越大,选的人就越多,R越小,选的人就越少. 那最小值就直接搞咯. 那 ...
- 93.快速搭建Web环境 Angularjs + Express3 + Bootstrap3
转自:https://www.cnblogs.com/wawahaha/p/3946023.html 前言 Angularjs越用越顺手,不仅代码量比jQuery少很多,而且实现思路特别清晰,构建大型 ...
- ie浏览器检测不到cookie的问题
之前做项目由于客户的要求设置缓存必须由后台来设置必须使用cookie(session是没问题的),后期设置时出现了登录页面与首页来还跳转的局面.原因就是首页没检测到登录后的缓存,而后台验证到确实已经是 ...
- 头像文件上传 方法一:from表单 方法二:ajax
方法一:from表单 html 设置form表单,内包含头像预览div,内包含上传文件input 设置iframe用来调用函数传参路径 <!--表单提交成功后不跳转处理页面,而是将处理数据返回给 ...
- 适配器模式(Adapter):类适配器、对象适配器
适配器模式(Adapter):将一个类的接口转换成客户希望的另外一个接口.A d a p t e r 模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作. 适用场景: 1.已经存在的类的接口 ...
- Eclipse使用struts2开发web应用快速搭建
eclipse 下载javaEE版,这里用4.5(Mars). Tomcat8解压,设置好JAVA_HOME环境变量. 下载struts2官网上的lib包,struts-2.3.24-lib.zip, ...