1018 锤子剪刀布 (20 分)
这个题,我做的时候一直以为是有捷径可循的,但是后来怎么想都想不出来。
只能暴力了,所谓暴力出奇迹,哈哈哈 代码如下:
#include<stdio.h>
int main()
{
int x,i,win=0,pin=0,lose=0,bu=0,ch=0,ji=0,bu1=0,ch1=0,ji1=0;
if(scanf("%d",&x));
char a[x],b[x];
for(i=0;i<x;i++)
{
getchar();
if(scanf("%c %c",&a[i],&b[i]));
if((a[i]=='B'&&b[i]=='C')||(a[i]=='C'&&b[i]=='J')||(a[i]=='J'&&b[i]=='B'))
{
win++;
if(a[i]=='B')
bu++;
else if(a[i]=='C')
ch++;
else
ji++;
}
if((a[i]=='B'&&b[i]=='J')||(a[i]=='J'&&b[i]=='C')||(a[i]=='C'&&b[i]=='B'))
{
lose++;
if(b[i]=='J')
ji1++;
else if(b[i]=='C')
ch1++;
else if(b[i]=='B')
bu1++;
}
if(a[i]==b[i])
pin++;
}
printf("%d %d %d\n",win,pin,lose);
printf("%d %d %d\n",lose,pin,win);
if((bu==ch&&ch==ji)||(bu==ch&&bu>ji)||(bu==ji&&bu>ch)||(bu>ch&&bu>ji))
printf("B ");
else if((ch==ji&&ch>bu)||(ch>ji&&ch>bu))
printf("C ");
else if(ji>bu&&ji>ch)
printf("J ");
if((bu1==ch1&&ch1==ji1)||(bu1==ch1&&bu1>ji1)||(bu1==ji1&&bu1>ch1)||(bu1>ch1&&bu1>ji1))
printf("B");
else if((ch1==ji1&&ch1>bu1)||(ch1>ji1&&ch1>bu1))
printf("C");
else if(ji1>bu1&&ji1>ch1)
printf("J");
return 0;
}
我一直在纠结的是这个 输出它是靠什么赢得最多 这个点,所以我每次都会去判断它是什么手势,它的结果如何。
额。。。下面分享一个大神的代码。。。大神果然不一样https://www.liuchuo.net/archives/539
代码如下:
using namespace std;
int main() {
int n;
cin >> n;
int jiawin = 0, yiwin = 0;
int jia[3] = {0}, yi[3] = {0};
for (int i = 0; i < n; i++) {
char s, t;
cin >> s >> t;
if (s == 'B' && t == 'C') {
jiawin++;
jia[0]++;
} else if (s == 'B' && t == 'J') {
yiwin++;
yi[2]++;
} else if (s == 'C' && t == 'B') {
yiwin++;
yi[0]++;
} else if (s == 'C' && t == 'J') {
jiawin++;
jia[1]++;
} else if (s == 'J' && t == 'B') {
jiawin++;
jia[2]++;
} else if (s == 'J' && t == 'C') {
yiwin++;
yi[1]++;
}
}
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] = {"BCJ"};
cout << str[maxjia] << " " << str[maxyi];
return 0;
}
来源:https://blog.csdn.net/qq_44622401/article/details/99047718