3311:满足下列情况的字符串AC,否则WA
1. there are only three distinct capital letters of the strings: Z, O, and J;
2. any string that is in the form xZOJxO is acceptable, where x is a string either empty or composed of O's only;
3. if aZbJc is acceptable, then aZbOJcO is acceptable, where a, b and c are all strings either empty or composed of O's only
Sample Input
ZOJO
OZOJOO
OZOOJOOO
OZOZOJOO
OOZOOJO
Sample Output
Accepted
Accepted
Accepted
Wrong Answer
Wrong Answer
思路:字符串拆分,统计前中后三部分个数。
注意Z和J的个数判断以及顺序判断。
一开始没判断顺序WA了好久。%>_<%
#include<iostream>
using namespace std;
#include<string.h>
#include<string>
string str;
int main()
{
bool isAC;
string left;
string top;
string mid;
string end;
while(cin>>str)
{
isAC = true;
if(str.find("Z")!=string::npos)
{
left = str.substr(str.find("Z")+1,str.length());
if(left.find("Z")!=string::npos)
isAC = false;
}
else
isAC=false;
if(str.find("J")!=string::npos)
{
left = str.substr(str.find("J")+1,str.length());
if(left.find("J")!=string::npos)
isAC = false;
}
else
isAC=false;
//J come before Z
if(str.find("J")<str.find("Z"))
isAC=false;
if(isAC)
{
top = str.substr(0,str.find("Z"));
mid = str.substr(str.find("Z")+1,str.find("J")-str.find("Z")-1);
end = str.substr(str.find("J")+1,str.length());
if(!(end.length()-top.length()==mid.length()&&mid.length()>=1))
isAC = false;
}
if(isAC)
cout<<"Accepted"<<endl;
else
cout<<"Wrong Answer"<<endl;
}
}
分享到:
相关推荐
zoj网站中多个练习的c++解答,文件名即为题目序号。经本人测试可以使用,主要为动态规划方面的问题,希望给初学者提供帮助。
训练时发现的好题目。#include #include int main() { char ch; char str[100]; while(gets(str)) { if(str[0] == 'E') return 0; int z = 0, o = 0, j = 0, i = 0; while(str[i] !...}
ZOJ完全解题报告,喜欢ACM的同学,欢迎下载
zoj 1140-zju 2433 简单题的部分答案 都是可以正确通过的,简洁易懂
zoj 3590 -3+1.md
ZOJ题解集合-截至2835。共1244个文件,C/C++,有重复
ZOJ 1055 Oh, Those Achin Feet.bfs求最短路径.
zoj 3212 K-Nice.md
ZOJ解题报告ZOJ解题报告ZOJ解题报告ZOJ解题报告
zoj 2561 Order-Preserving Codes.md
zoj题目简单归类zoj题目简单归类zoj题目简单归类
NULL 博文链接:https://weitch.iteye.com/blog/1006972
acm中zoj1002的可运行C++程序
包含了zoj700多道题目的源代码,在做题时可以参考
Problem Arrangement zoj 3777
ZOJ题目答案源码
学习ACM程序设计的朋友一定要看,这是训练必备的POJ ZOJ题目分类及解题思路
一个非常非常非常非常实用的zoj结题代码
zoj 1003 c语言的,要写这么多描述吗。。
浙大ZOJ题目分类,可以让你更方便快速锁定那你想要联系的题目,是自己快速提高·