Description Uncle Fyodor, Matroskin the Cat and Sharic the Dog live theirsimple but happy lives in Prostokvashino. Sometimes they receiveparcels from Uncle Fyodor’s parents and sometimes from anonymousbenefactors, in which case it is hard to determine to which one ofthem the package has been sent. A photographic rifle is obviouslyfor Sharic who loves hunting and fish is for Matroskin, but forwhom was a new video game console meant? Every one of the threefriends claimed that the present is for him and nearly quarreled.Uncle Fyodor had an idea how to solve the problem justly: theyshould suppose that the console was sent to all three of them andplay it in turns. Everybody got relieved but then yet anotherburning problem popped up — who will play first? This timeMatroskin came up with a brilliant solution, suggesting the mostfair way to find it out: play rock-paper-scissors together. Therules of the game are very simple. On the count of three everyplayer shows a combination with his hand (or paw). The combinationcorresponds to one of three things: a rock, scissors or paper. Someof the gestures win over some other ones according to well-knownrules: the rock breaks the scissors, the scissors cut the paper,and the paper gets wrapped over the stone. Usually there are twoplayers. Yet there are three friends, that’s why they decided tochoose the winner like that: If someone shows the gesture that winsover the other two players, then that player wins. Otherwise,another game round is required. Write a program that will determinethe winner by the gestures they have shown. Input The first input line contains the name of the gesture that UncleFyodor showed, the second line shows which gesture Matroskin showedand the third line shows Sharic’s gesture. Output Print "F" (without quotes) if Uncle Fyodor wins. Print "M" ifMatroskin wins and "S" if Sharic wins. If it is impossible to findthe winner, print "?". Sample Input
Input
rock rock rock
Output
?
Input
paper rock rock
Output
F
Input
scissors rock rock
Output
?
Input
scissors paper rock
Output
? |
可用判断字符串长度的方法(此题所给单词长度刚好都不一样!!)
#include<iostream> using namespace std; int main() { char a[30],b[10],c[10],d[10]; while(cin>>b>>c>>d) { strcpy(a,b); strcat(a,c);strcat(a,d); if(!strcmp(a,"rockscissorsscissors")||!strcmp(a,"scissorspaperpaper")||!strcmp(a,"paperrockrock")) { cout<<"F"<<endl;continue;} if(!strcmp(a,"scissorsrockscissors")||!strcmp(a,"paperscissorspaper")||!strcmp(a,"rockpaperrock")) { cout<<"M"<<endl;continue;} if(!strcmp(a,"scissorsscissorsrock")||!strcmp(a,"paperpaperscissors")||!strcmp(a,"rockrockpaper")) cout<<"S"<<endl; else cout<<"?"<<endl; } return 0; }