九度OJ 1006 ZOJ

#include <iostream>
#include <string>
using namespace std;
int getO(string str,int &start,char ch)
{
int count=;
for(;start<str.length();start++)
{
if(str[start] == 'o')
{
count++;
}
else if(str[start]==ch)
{
start++;
return count;
}
else
return INT_MIN;
}
return INT_MIN;
}
int main()
{
string str;
while(cin>>str)
{
//char c = str.at(1);
//cout<<c;//input abc, return b //cout<<str.capacity()<<endl;//return str's size,but must be 4n;
//str.clear();
//cout<<str;
//cout<<str.compare("abc");//same as strcmp()
//cout<<str.find_first_of('o');//find first pos of 'o'
//cout<<str.append("abc");//add "abc" after str
//cout<<*str.begin();//same as begin() in vector,so is end()
//int flag = str.find("ab");//return the pos of "ab" in str,-1 will return if not find
//cout<<str.length()<<endl;//return str's length,example:"abc"->3 //str.erase(str.begin());//remove the char which is pointed by iterator
//cout<<str.find_last_of('o')<<endl;//find last pos of char
//str.push_back('a');//pushback one char str.push_back('x');
int pos1 = str.find("z");
int pos2 = str.find("j");
int start = ;
int a = getO(str,start,'z');
int b = getO(str,start,'j');
int c = getO(str,start,'x');
// cout<<a<<b<<c<<endl; if(a==INT_MIN || b==INT_MIN || c==INT_MIN || b==)
{
cout<<"Wrong Answer"<<endl;
continue;
}
c-=(b-)*a;
if(a==c)
cout<<"Accepted"<<endl;
else
cout<<"Wrong Answer"<<endl;
} return ;
}
题目描述:
对给定的字符串(只包含'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”。
样例输入:
zoj
ozojo
ozoojoo
oozoojoooo
zooj
ozojo
oooozojo
zojoooo
样例输出:
Accepted
Accepted
Accepted
Accepted
Accepted
Accepted
Wrong Answer
Wrong Answer 分析:由其生成串的算法可以得出,azbjc为其串的一般式,其中a,b,c表示开始字符到z之间o的数量,b表示字符z到j之间o的数量,c表示字符j到字符串末尾o的数量,且有a=c-(b-1)*a,且b>=1,请注意b=0的情况,应该为wrong answer!
上一篇:QT in VS 多语言实现(中英文切换,每个步骤都有截图,只有UTF8才能让Qt语言家正确读取。先qApp->removeTranslator,然后installTranslator,每个类都要写上槽函数RetranslateUI)


下一篇:UC和QQ两个主流浏览器 * 点击触发微信分享到朋友圈或发送给朋友的功能(转载)