題目描述: 對給定的字符串(只包含'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
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string str;
while(cin>>str)
{
size_t a = str.find_first_not_of("o");
if (a==string::npos || str[a]!='z')
{
cout<<"Wrong Answer"<<endl;
continue;
}
size_t b = str.find_first_not_of("o",a+1);
if (b==string::npos || b==a+1||str[b]!='j')
{
cout<<"Wrong Answer"<<endl;
continue;
}
size_t c = str.find_first_not_of("o",b+1);
if (c!=string::npos)
{
cout<<"Wrong Answer"<<endl;
continue;
}
if (a*(b-a-1)!=str.size()-b-1)
{
cout<<"Wrong Answer"<<endl;
continue;
}
else
{
cout<<"Accepted"<<endl;
continue;
}
}
return 0;
}