1. 程式人生 > >C語言訓練-2733-小鑫の日常系列故事(二)——石頭剪子布

C語言訓練-2733-小鑫の日常系列故事(二)——石頭剪子布

Problem Description
小鑫在上幼兒園的時候,喜歡跟小夥伴健健玩石頭剪子布的遊戲 ,你能幫他們判斷誰勝誰負麼?
Input
輸入有兩行,每一行都有可能為“Rock”(石頭),“Scissors”(剪子),”Cloth”(布)。第一行為小鑫的選擇,第二行為健健的選擇。
Output
輸出有一行,如果小鑫贏了輸出“Win”,輸了輸出“Lose”,平局輸出“Equal”。(輸出不包括引號)
Sample Input
Rock
Scissors
Sample Output
Win

//注
strcmp 編輯
C/C++函式,比較兩個字串
設這兩個字串為str1,str2,
若str1==str2,則返回零;
若str1<str2,則返回負數;
若str1>str2,則返回正數。
matlab中函式,strcmp(s1,s2) 判斷兩個字串s1和s2是否相同,相同返回true ,不同返回false

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
  char a[100],b[100];
  cin>>a;
  cin>>b;
  if (strcmp(a, "Rock") == 0 && strcmp(b, "Rock") == 0)
      printf("Equal\n");
  if (strcmp(a, "Rock") == 0 && strcmp(b, "Scissors") == 0)
      printf("Win\n");
  if (strcmp(a, "Rock") == 0 && strcmp(b, "Cloth") == 0)
      printf("Lose\n");
  if (strcmp(a, "Scissors") == 0 && strcmp(b, "Scissors") == 0)
      printf("Equal\n");
  if (strcmp(a, "Scissors") == 0 && strcmp(b, "Rock") == 0)
      printf("Lose\n");
  if (strcmp(a, "Scissors") == 0 && strcmp(b, "Cloth") == 0)
      printf("Win\n");
  if (strcmp(a, "Cloth") == 0 && strcmp(b, "Cloth") == 0)
      printf("Equal\n");
  if (strcmp(a, "Cloth") == 0 && strcmp(b, "Rock") == 0)
      printf("Win\n");
  if (strcmp(a, "Cloth") == 0 && strcmp(b, "Scissors") == 0)
      printf("Lose\n");
return 0;
}