PTA 1018 錘子剪刀布 c語言

2021-09-26 01:39:38 字數 1020 閱讀 6783

這個題,我做的時候一直以為是有捷徑可循的,但是後來怎麼想都想不出來。

只能暴力了,所謂暴力出奇蹟,哈哈哈 **如下:

#includeint main()

我一直在糾結的是這個 輸出它是靠什麼贏得最多 這個點,所以我每次都會去判斷它是什麼手勢,它的結果如何。

額。。。下面分享乙個大神的**。。。大神果然不一樣

**如下:

using namespace std;

int main() , yi[3] = ;

for (int i = 0; i < n; i++) else if (s == 'b' && t == 'j') else if (s == 'c' && t == 'b') else if (s == 'c' && t == 'j') else if (s == 'j' && t == 'b') else if (s == 'j' && t == 'c')

}cout << jiawin << " " << n - jiawin - yiwin << " " << yiwin << endl << yiwin << " " << n - jiawin - yiwin << " " << jiawin << endl;

int maxjia = jia[0] >= jia[1] ? 0 : 1;

maxjia = jia[maxjia] >= jia[2] ? maxjia : 2;

int maxyi = yi[0] >= yi[1] ? 0 : 1;

maxyi = yi[maxyi] >= yi[2] ? maxyi : 2;

char str[4] = ;

cout << str[maxjia] << " " << str[maxyi];

return 0;

}

PTA 1018 錘子剪刀布 20分

大家應該都會玩 錘子剪刀布 的遊戲 兩人同時給出手勢,勝負規則如圖所示 現給出兩人的交鋒記錄,請統計雙方的勝 平 負次數,並且給出雙方分別出什麼手勢的勝算最大。輸入格式 輸入第 1 行給出正整數 n 10 5 即雙方交鋒的次數。隨後 n 行,每行給出一次交鋒的資訊,即甲 乙雙方同時給出的的手勢。c ...

PTA題目 1018錘子剪刀布

這是以前寫的 可以參考一下 include static int cnt win 0,cnt draw 0,cnt lost 0 以a記錄輸贏次數 static int a c cnt 0,a j cnt 0,a b cnt 0 a用各手勢贏的次數 static int b c cnt 0,b j ...

1018 錘子剪刀布,C

include intmain char b 1000 int i 0,c1 0,c2 0,c3 0,d1 0,d2 0,d3 0,j 0,h 0,n int cc 0,cb 0,cj 0,dc 0,db 0,dj 0,m 0 scanf d n n while n 1 n 1是為了減少一次輸入,在...