返回列表 發帖

607 撲克牌比大小

1. 題目說明:
請依下列題意進行作答,使輸出值符合題意要求。

2. 設計說明:
請撰寫一程式,製作撲克牌比大小遊戲,讓使用者輸入兩張牌,比較兩張牌的大小並將結果輸出。
撲克牌比大小規則:每張牌分別以英文及數字表示,其中S代表黑桃、H代表紅心、D代表方塊、C代表梅花,數字為1~13。首先比較花色:黑桃>紅心>方塊>梅花;當花色相同時,再比較數字:13最大、1最小。
提示:數字「0」的ASCII碼=48。
提示:若使用 Java 語言答題,請以「JP」開頭命名包含 main 靜態方法的 class,評測系統才能正確評分。

3. 輸入輸出:
輸入說明
兩張撲克牌,以英文(S、H、D、C)及數字(1~13)表示

輸出說明
兩張撲克牌比大小結果

範例輸入1
S1 D13
範例輸出1
S1 > D13

範例輸入2
C5 C5
範例輸出2
C5 = C5

本帖隱藏的內容需要回復才可以瀏覽

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. string s1, s2, w = "CDHS";
  4. int main()
  5. {
  6.     cin>>s1>>s2;
  7.     int w1 = w.find(s1[0]);
  8.     int w2 = w.find(s2[0]);
  9.     if(w1 > w2)
  10.         cout<<s1<<" > "<<s2<<endl;
  11.     else if(w1 < w2)
  12.         cout<<s1<<" < "<<s2<<endl;
  13.     else
  14.     {
  15.         int i1 = stoi(s1.substr(1));
  16.         int i2 = stoi(s2.substr(1));
  17.         if(i1 > i2)
  18.             cout<<s1<<" > "<<s2<<endl;
  19.         else if(i1 < i2)
  20.             cout<<s1<<" < "<<s2<<endl;
  21.         else
  22.             cout<<s1<<" = "<<s2<<endl;
  23.     }
  24.     return 0;
  25. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. string s1, s2, w="CDHS";
  4. int main()
  5. {
  6.     cin>>s1>>s2;
  7.     int w1=w.find(s1[0]);
  8.     int w2=w.find(s2[0]);
  9.     if(w1>w2)
  10.         cout<<s1<<" > "<<s2;
  11.     else if(w1<w2)
  12.         cout<<s1<<" < "<<s2;
  13.     else
  14.     {
  15.         int i1=stoi(s1.substr(1));
  16.         int i2=stoi(s2.substr(1));
  17.         if(i1>i2)
  18.             cout<<s1<<" > "<<s2;
  19.         else if(i1<i2)
  20.             cout<<s1<<" < "<<s2;
  21.         else
  22.             cout<<s1<<" = "<<s2;
  23.     }
  24.     return 0;
  25. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. string s1,s2,w="CDHS";
  4. int main()
  5. {
  6.     cin>>s1>>s2;
  7.     int w1=w.find(s1[0]);
  8.     int w2=w.find(s2[0]);
  9.     if(w1>w2)
  10.         cout<<s1<<" > "<<s2;
  11.     else if(w1<w2)
  12.         cout<<s1<<" < "<<s2;
  13.     else
  14.     {
  15.         int i1=stoi(s1.substr(1));
  16.         int i2=stoi(s2.substr(1));
  17.         if(i1>i2)
  18.             cout<<s1<<" > "<<s2;
  19.         else if(i1<i2)
  20.             cout<<s1<<" < "<<s2;
  21.         else
  22.             cout<<s1<<" = "<<s2;
  23.     }
  24.     return 0;
  25. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. string s1,s2,w="CDHS";
  4. int main()
  5. {
  6.     cin>>s1>>s2;
  7.     int w1=w.find(s1[0]);
  8.     int w2=w.find(s2[0]);
  9.     if(w1>w2)
  10.         cout<<s1<<" > "<<s2<<endl;
  11.     else if(w1<w2)
  12.         cout<<s1<<" < "<<s2<<endl;
  13.     else
  14.     {
  15.         int i1=stoi(s1.substr(1));
  16.         int i2=stoi(s2.substr(1));
  17.         if(i1>i2)
  18.             cout<<s1<<" > "<<s2<<endl;
  19.         else if(i1<i2)
  20.             cout<<s1<<" < "<<s2<<endl;
  21.         else
  22.             cout<<s1<<" = "<<s2<<endl;
  23.     }
  24.     return 0;
  25. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. string s1,s2,w="CDHS";
  4. int main()
  5. {
  6.     cin>>s1>>s2;
  7.     int w1=w.find(s1[0]);
  8.     int w2=w.find(s2[0]);
  9.     if(w1>w2)
  10.         cout<<s1<<" > "<<s2;
  11.     else if(w1<w2)
  12.         cout<<s1<<" < "<<s2;
  13.     else
  14.     {
  15.         int i1=stoi(s1.substr(1));
  16.         int i2=stoi(s2.substr(1));
  17.         if(i1>i2)
  18.             cout<<s1<<" > "<<s2<<endl;
  19.         else if(i1<i2)
  20.             cout<<s1<<" < "<<s2<<endl;
  21.         else
  22.             cout<<s1<<" = "<<s2<<endl;
  23.     }
  24.     return 0;
  25. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. string s1,s2,w="CDHS";
  4. int main(){
  5.     cin>>s1>>s2;
  6.     int w1=w.find(s1[0]);
  7.     int w2=w.find(s2[0]);
  8.     if(w1>w2)
  9.         cout<<s1<<" > "<<s2<<endl;
  10.     else if(w1<w2)
  11.         cout<<s1<<" < "<<s2<<endl;
  12.     else{
  13.         int i1=stoi(s1.substr(1));
  14.         int i2=stoi(s2.substr(1));
  15.         if(i1>i2)
  16.             cout<<s1<<" > "<<s2<<endl;
  17.         else if(i1<i2)
  18.             cout<<s1<<" < "<<s2<<endl;
  19.         else
  20.             cout<<s1<<" = "<<s2<<endl;
  21.     }
  22.     return 0;
  23. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. string s1,s2,w="CDHS";
  4. int main()
  5. {
  6.     cin>>s1>>s2;
  7.     int w1=w.find(s1[0]);
  8.     int w2=w.find(s2[0]);
  9.     if(w1>w2)
  10.         cout<<s1<<" > "<<s2;
  11.     else if(w1<w2)
  12.         cout<<s1<<" < " <<s2;
  13.     else
  14.     {
  15.         int i1=stoi(s1.substr(1));
  16.         int i2=stoi(s2.substr(1));
  17.         if(i1>i2)
  18.             cout<<s1<<" > "<<s2<<endl;
  19.         else if(i1<i2)
  20.             cout<<s1<<" < "<<s2<<endl;
  21.         else
  22.             cout<<s1<<" = "<<s2<<endl;
  23.     }
  24.     return 0;
  25. }
複製代碼

TOP

返回列表