// Javier Gomez Serrano // Randomized solution for genetics // At each step, does any simplification (if possible) or // if there isn't any, cuts and pastes randomly #include #include #include #include using namespace std; string transform(string& s, int & arms, int& legs){ // Rule 1 for (int i=0;i= 'A' && randchar <= 'Z') randchar+='a' - 'A'; // Cut int pos1,pos2; pos1 = -1; pos2 = -1; for (int i=0;i=0; i--){ if (t2[i] >= 'a' && t2[i] <='z'){ t3 = t3 + (char)(t2[i]+'A'-'a'); } else t3 = t3 + (char)(t2[i]+'a'-'A'); } t2 = t3; pos2 = t3.size() - pos2 - 1; } //cout << "t1 = " << t1 << " t2 = " << t2 << endl; string p1,p2,p3,p4; p1 = t1.substr(0,pos1); p2 = t1.substr(pos1+1,t1.size() - pos1); p3 = t2.substr(0,pos2); p4 = t2.substr(pos2+1,t2.size() - pos2); //cout << "p1 = " << p1 << " p2 = " << p2 << " p3 = " << p3 << " p4 = " << p4 << endl; string t5,t6; t5 = p1 + p4; t6 = p3 + p2; //cout << "t5 = " << t5 << " t6 = " << t6 << endl; string tot = t5 + (char)randchar + t6; if (dif) tot += (char)(randchar + 'A'-'a'); else tot+=(char)randchar; //cout << "tot = " << tot << endl; return tot; } int main(){ srand(time(0)); string s; while (cin >> s, s != "END"){ int arms, legs; legs = 0; arms = 0; while (1){ //cout << "s antes = " << s << endl; s = transform(s,arms,legs); //cout << "s despues = " << s << endl; if (legs > 0 && arms > 0){ arms+=2*legs; legs = 0; } if (s == "") break; } if (arms == 0 && legs != 0){ cout << legs << " leg"; if (legs > 1) cout << "s"; cout << endl; } else if (arms != 0 && legs == 0){ cout << arms << " arm"; if (arms > 1) cout << "s"; cout << endl; } else cout << "none" << endl; } return 0; }