标签:style blog io ar color os sp for strong
#include <iostream> #include <string> using namespace std; int getO(string str,int &start,char ch) { int count=0; 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 = 0; 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==0) { cout<<"Wrong Answer"<<endl; continue; } c-=(b-1)*a; if(a==c) cout<<"Accepted"<<endl; else cout<<"Wrong Answer"<<endl; } return 0; }
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!
标签:style blog io ar color os sp for strong
原文地址:http://www.cnblogs.com/55open/p/4111763.html