当前位置:网站首页>1018 锤子剪刀布
1018 锤子剪刀布
2022-06-29 04:09:00 【乐乐~LL】
大家应该都会玩“锤子剪刀布”的游戏:两人同时给出手势,胜负规则如图所示:

现给出两人的交锋记录,请统计双方的胜、平、负次数,并且给出双方分别出什么手势的胜算最大。
输入格式:
输入第 1 行给出正整数 N(≤105),即双方交锋的次数。随后 N 行,每行给出一次交锋的信息,即甲、乙双方同时给出的的手势。C 代表“锤子”、J 代表“剪刀”、B 代表“布”,第 1 个字母代表甲方,第 2 个代表乙方,中间有 1 个空格。
输出格式:
输出第 1、2 行分别给出甲、乙的胜、平、负次数,数字间以 1 个空格分隔。第 3 行给出两个字母,分别代表甲、乙获胜次数最多的手势,中间有 1 个空格。如果解不唯一,则输出按字母序最小的解。
输入样例:
10
C J
J B
C B
B B
B C
C C
C B
J B
B C
J J
输出样例:
5 3 2
2 3 5
B B代码如下:
#include<stdio.h>
int main()
{
int n, j, i, k;
char a, b, f;
char ar[3] = { 0 };
char br[3] = { 0 };
scanf("%d", &n);
getchar();
int arr[3] = { 0 };
int shena[3] = { 0 };
int shenb[3] = { 0 };
for (i = 0; i < n; i++)
{
scanf("%c %c", &a, &b);
getchar();
if ((a == 'C' && b == 'J') || (a == 'J' && b == 'B') || (a == 'B' && b == 'C'))
{
arr[0]++;//胜
if (a == 'C')
{
shena[0]++;
ar[0] = 'C';
}
else if (a == 'J')
{
shena[1]++;
ar[1] = 'J';
}
else
{
shena[2]++;
ar[2] = 'B';
}
}
else if ((a == 'C' && b == 'B') || (a == 'J' && b == 'C') || (a == 'B' && b == 'J'))
{
arr[1]++;//负
if (b == 'C')
{
shenb[0]++;
br[0] = 'C';
}
else if (b == 'J')
{
shenb[1]++;
br[1] = 'J';
}
else
{
shenb[2]++;
br[2] = 'B';
}
}
else
arr[2]++;
}
printf("%d %d %d\n", arr[0], arr[2], arr[1]);
printf("%d %d %d\n", arr[1], arr[2], arr[0]);
//shena 0-C 1-J 2-B
for (i = 0; i < 3 - 1; i++)
{
for (j = 0; j < 3 - i - 1; j++)
{
if (shena[j] > shena[j + 1])
{
k = shena[j];
shena[j] = shena[j + 1];
shena[j + 1] = k;
f = ar[j];
ar[j] = ar[j + 1];
ar[j + 1] = f;
}
}
}
if (shena[0] == shena[1] && shena[1] == shena[2])
printf("B");
else if (shena[1] == shena[2])
{
if (ar[1] < ar[2])
printf("%c", ar[1]);
else
printf("%c", ar[2]);
}
else
printf("%c", ar[2]);
for (i = 0; i < 3 - 1; i++)
{
for (j = 0; j < 3 - i - 1; j++)
{
if (shenb[j] > shenb[j + 1])
{
k = shenb[j];
shenb[j] = shenb[j + 1];
shenb[j + 1] = k;
f = br[j];
br[j] = br[j + 1];
br[j + 1] = f;
}
}
}
if (shenb[0] == shenb[1] && shenb[1] == shenb[2])
printf(" B");
else if (shenb[1] == shenb[2])
{
if (br[1] < br[2])
printf(" %c", br[1]);
else
printf(" %c", br[2]);
}
else
printf(" %c", br[2]);
printf("\n");
return 0;
}边栏推荐
- Idea modifying JVM memory
- Yangzhou needs one English IT Helpdesk Engineer -20220216
- Baidu AI Cloud service grid product CSM release 𞓜 hot public beta
- The great gods take connections from the MySQL connection pool in the open of the rich function. The initialization of the connection pool is 20. If the parallelism of the rich function is 1
- SEAttention 通道注意力機制
- Data collection and management [7]
- CDC2.2.1还不支持postgresql14.1么?基于pgbouncer连接方式下,以5433
- String不同创建方式的区别
- Ansible最佳实践之Playbook不同上下文提权Demo
- New listing of operation light 3.0 -- a sincere work of self subversion across the times
猜你喜欢

Tech Cloud Report: Mixed Office B side: How Safety and Efficiency can be combined?

How sqlserver queries and removes results with null fields in the whole column

SEAttention 通道注意力機制

Runtimeerror in yolox: dataloader worker (PID (s) 17724, 1364, 18928) exited unexpectedly

【新功能】Ambire 钱包集成了 Metis 网络

科班出身,结果外包都不要

Live broadcast preview | neurips special session I & Young Scientists special session

Build a simple website by yourself

If I hadn't talked to Ali P7, I wouldn't know I was a mallet

【C语言】 详解线程退出函数 pthread_exit
随机推荐
Qtableview gets all currently selected cells
webassembly学习-动态链接
泠静的想一想自己的路
Wi-Fi 7 来啦,它到底有多强?
[FPGA mathematical formula] use FPGA to realize common mathematical formulas
Seura 2 test code summary
CANoe-如何在Trace窗口解析报文并显示信息(Program Node和结构体类型系统变量的使用)
Data statistical analysis (SPSS) [5]
Ask the handler about the memory leak scenario in the interview. Don't just know static internal classes & weak references!
[MCU framework][dfu] DFU upgrade example with CRC verification + timeout mechanism +led indicator + chip locking + chip self erasure
【新功能】Ambire 钱包集成了 Metis 网络
为什么说测试岗位是巨坑?8年测试人告诉你千万别上当
New listing of operation light 3.0 -- a sincere work of self subversion across the times
科技云报道:混合办公的B面:安全与效率如何兼得?
String differences between different creation methods
Error accessing database
Data collection and management [3]
【C语言】解决 “address of stack memory associated with local variable ‘num‘ returned”
Logstash starts too slowly or even gets stuck
Seattention channel attention mechanism