標題:
607 撲克牌比大小
[打印本頁]
作者:
方浩葦
時間:
2024-5-15 13:52
標題:
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
本帖隱藏的內容需要回復才可以瀏覽
作者:
宥竣
時間:
2024-5-18 20:02
#include <bits/stdc++.h>
using namespace std;
string s1,s2,w="CDHS";
int main()
{
cin>>s1>>s2;
int w1=w.find(s1[0]),w2=w.find(s2[0]);
if(w1>w2) cout<<s1<<" > "<<s2;
else if(w1<w2) cout<<s1<<" < "<<s2;
else
{
int n1=stoi(s1.substr(1)),n2=stoi(s2.substr(1));
if(n1>n2) cout<<s1<<" > "<<s2;
else if(n1<n2) cout<<s1<<" < "<<s2;
else cout<<s1<<" = "<<s2;
}
return 0;
}
複製代碼
作者:
張博翔
時間:
2024-5-18 20:02
#include<bits/stdc++.h>
using namespace std;
string s1,s2,w="CDHS";
int main()
{
cin>>s1>>s2;
int w1=w.find(s1[0]);
int w2=w.find(s2[0]);
if(w1>w2)
cout<<s1<<" > "<<s2;
else if(w1<w2)
cout<<s1<<" < "<<s2;
else
{
int i1=stoi(s1.substr(1));
int i2=stoi(s2.substr(1));
if(i1>i2)
cout<<s1<<" > "s2;
else if(i1<i2)
cout<<s1<<" < "s2;
else
cout<<s1<<" = "s2;
}
return 0;
}
複製代碼
作者:
楊惇翔
時間:
2024-5-18 20:03
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s1,s2,w="CDHS";
cin>>s1>>s2;
int w1=w.find(s1[0]);
int w2=w.find(s2[0]);
if(w1>w2)
cout<<s1<<" > "<<s2;
else if(w1<w2)
cout<<s1<<" < "<<s2;
else
{
int i1=stoi(s1.substr(1));
int i2=stoi(s2.substr(1));
if(i1>i2)
cout<<s1<<" > "<<s2;
else if(i1<i2)
cout<<s1<<" < "<<s2;
else
cout<<s1<<" = "<<s2;
}
return 0;
}
複製代碼
作者:
盧禹丞
時間:
2024-5-18 20:07
#include<bits/stdc++.h>
using namespace std;
string s1,s2,w="CDHS";
int main()
{
cin>>s1>>s2;
int w1=w.find(s1[0]);
int w1=w.find(s1[0]);
if(w1>w2)
cout<<s1<<">"<<s2;
else if(w1<w2)
cout<<s1<<"<"<<s2;
else
{
int i1=stoi(s1.substr(1));
int i2=stoi(s2.substr(1));
if(i1>i2)
cout<<s1<<">"<<s2;
else if(i1<i2)
cout<<s1<<"<"<<s2;
else
cout<<s1<<"="<<s2;
}
return 0;
}
複製代碼
作者:
林哲弘
時間:
2024-5-18 20:18
#include <bits/stdc++.h>
using namespace std;
string s1,s2,w="CDHS";
int main()
{
cin>>s1>>s2;
int w1=w.find(s1[0]);
int w2=w.find(s2[0]);
if(w1>w2)
cout<<s1<<" > "<<s2;
else if(w1<w2)
cout<<s1<<" < "<<s2;
else
{
int i1=stoi(s1.substr(1));
int i2=stoi(s2.substr(1));
if(i1>i2)
cout<<s1<<" > "<<s2;
else if(i1<i2)
cout<<s1<<" < "<<s2;
else
cout<<s1<<" = "<<s2;
}
return 0;
}
複製代碼
作者:
博勛
時間:
2024-5-18 20:19
#include<bits/stdc++.h>
using namespace std;
string s1,s2,w="CDHS";
int main()
{
cin>>s1>>s2;
int w1=w.find(s1[0]);
int w2=w.find(s2[0]);
if(w1>w2)
cout<<s1<<" > "<<s2;
else if(w1<w2)
cout<<s1<<" < "<<s2;
else
{
int i1=stoi(s1.substr(1));
int i2=stoi(s2.substr(1));
if(i1>i2)
cout<<s1<<" > "<<s2;
else if(i1<i2)
cout<<s1<<" < "<<s2;
else
cout<<s1<<" = "<<s2;
}
return 0;
}
複製代碼
作者:
黃兆駿
時間:
2024-5-18 20:32
#include<bits/stdc++.h>
using namespace std;
string s1,s2,w="CDHS";
int main()
{
cin>>s1>>s2;
int w1=w.find(s1[0]);
int w2=w.find(s2[0]);
if(w1>w2)
cout<<s1<<" > "<<s2;
else if(w1<w2)
cout<<s1<<" < "<<s2;
else
{
int i1=stoi(s1.substr(1));
int i2=stoi(s2.substr(1));
if(i1>i2)
cout<<s1<<" > "<<s2;
else if(i1<i2)
cout<<s1<<" < "<<s2;
else
cout<<s1<<" = "<<s2;
}
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2