当前位置:网站首页>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;
}边栏推荐
- 【C语言】 详解线程退出函数 pthread_exit
- Black screen and error reporting when loading custom models for gazebo with roslaunch
- 二叉树序列化与反序列化(leetcode(困难))
- Data statistical analysis (SPSS) [6]
- 多机局域网办公神器 rustdesk 使用强推!!!
- String不同创建方式的区别
- Mécanisme d'attention du canal de fixation
- leetcode - 295. Median data flow
- JSX的基本使用
- CDC2.2.1还不支持postgresql14.1么?基于pgbouncer连接方式下,以5433
猜你喜欢

Implementation of thread pool based on variable parameter template

leetcode - 295. Median data flow

Libuv library overview and comparison of libevent, libev and libuv (Reprint)
![[fpga+sin] FPGA implementation of sinusoidal signal generator module based on DDS (direct digital synthesis)](/img/7d/d507d435fe97de005e20560fd6ba35.png)
[fpga+sin] FPGA implementation of sinusoidal signal generator module based on DDS (direct digital synthesis)

sql两列变为多行过滤显示

moudo网络库剖析

c语言 --- 分支结构

Microsecond TCP timestamp

Wi-Fi 7 来啦,它到底有多强?

Technology cloud report: side B of mixed office: how to have both security and efficiency?
随机推荐
Ansible最佳实践之Playbook不同上下文提权Demo
Data collection and management [6]
开发者方案 · 环境监测设备(小熊派物联网开发板)接入涂鸦IoT开发平台
Cloud native weekly | grafana 9 was officially released; The Chinese version of cloud native vocabulary is now online
Black screen and error reporting when loading custom models for gazebo with roslaunch
Apifox : 不仅是Api调试工具,更是开发团队的协作神器
Data statistical analysis (SPSS) [3]
PostgreSQL 出现cross-database references are not implemented的bug
智能视觉组比赛流程草案
Data collection and management [5]
Libuv library overview and comparison of libevent, libev and libuv (Reprint)
lua-protobuff emmy-lua 轮子
【布里渊现象】光纤布里渊温度和应变分布同时测量系统研究
项目开发修养
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
[Brillouin phenomenon] Study on simultaneous measurement system of Brillouin temperature and strain distribution in optical fiber
Logstash starts too slowly or even gets stuck
Technology cloud report: side B of mixed office: how to have both security and efficiency?
【C语言】详解线程回收函数 pthread_join
Anaconda自带的Spyder编辑器启动报错问题