时间限制:1秒
空间限制:65536K
热度指数:395
算法知识视频讲解
题目描述
对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC。 是否AC的规则如下: 1. zoj能AC; 2. 若字符串形式为xzojx,则也能AC,其中x可以是N个'o' 或者为空; 3. 若azbjc 能AC,则azbojac也能AC,其中a,b,c为N个'o'或者为空;
输入描述:
输入包含多组测试用例,每行有一个只包含'z','o','j'三种字符的字符串,字符串长度小于等于1000。
输出描述:
对于给定的字符串,如果能AC则请输出字符串“Accepted”,否则请输出“Wrong Answer”。
示例1
输入
zoj ozojo ozoojoo oozoojoooo zooj ozojo oooozojo zojoooo
输出
Accepted Accepted Accepted Accepted Accepted Accepted Wrong Answer
Wrong Answer
z和j之间有几个o,说明末尾的o的个数是开头的几倍
//#include "stdafx.h"
#include"stdio.h"
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
const int maxn=1000000;
string s;
int count(char x){
int ans=0;
for(int i=0;i<s.length();i++)
if(s[i]==x)ans++;
return ans;
}
int main(){
//freopen("c://jin.txt","r",stdin);
while(cin>>s){
int z=s.find_first_of('z');
int j=s.find_first_of('j');
if(count('z')==1&&count('j')==1){
int o=j-z-1;
int o1=z;
int o2=s.length()-j-1;
if(o!=0&&o1*o==o2){
cout<<"Accepted"<<endl;
}
else cout<<"Wrong Answer"<<endl;
}
else cout<<"Wrong Answer"<<endl;
}
// freopen("CON","r",stdin);
// system("pause");
return 0;
}