当前位置:网站首页>1018 hammer scissors cloth
1018 hammer scissors cloth
2022-06-29 04:11:00 【Lele ~ll】
Everyone should be able to play “ Hammer scissors ” The game of : Both of them make gestures at the same time , The winning and losing rules are as shown in the figure :

Now give the record of the two men's confrontation , Please count the wins of both sides 、 flat 、 Negative times , And give the two sides respectively out what gesture has the greatest chance of winning .
Input format :
Enter the first 1 Line gives a positive integer N(≤105), That is, the number of confrontation between the two sides . And then N That's ok , Each line gives the message of a confrontation , Namely a 、 Gestures given by both parties at the same time .C representative “ The hammer ”、J representative “ scissors ”、B representative “ cloth ”, The first 1 Two letters represent Party A , The first 2 On behalf of Party B , There is 1 A space .
Output format :
Output No 1、2 Lines give a respectively 、 B's victory 、 flat 、 Negative times , Between the numbers 1 Space separation . The first 3 The line gives two letters , Each represents a 、 B the gesture that wins the most times , There is 1 A space . If the solution is not unique , The solution with the smallest alphabetical order is output .
sample input :
10
C J
J B
C B
B B
B C
C C
C B
J B
B C
J J
sample output :
5 3 2
2 3 5
B BThe code is as follows :
#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]++;// negative
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;
}边栏推荐
- Qtableview gets all currently selected cells
- String differences between different creation methods
- Ling Jing thinks about her own way
- 干货丨微服务架构是什么?有哪些优点和不足?
- Libuv库概述及libevent、libev、libuv对比(转载)
- MySQL column to row conversion without Union
- Apifox : 不仅是Api调试工具,更是开发团队的协作神器
- 情绪的变化需要控制
- CDC2.2.1还不支持postgresql14.1么?基于pgbouncer连接方式下,以5433
- Project development culture
猜你喜欢
![[C language] explain the thread exit function pthread_ exit](/img/fb/96db1c712370dbb216a06440ecdc5e.png)
[C language] explain the thread exit function pthread_ exit
![[Brillouin phenomenon] Study on simultaneous measurement system of Brillouin temperature and strain distribution in optical fiber](/img/92/57792ef733964230d36e0b9bb218b4.png)
[Brillouin phenomenon] Study on simultaneous measurement system of Brillouin temperature and strain distribution in optical fiber

Mobileone: the mobile terminal only needs 1ms of high-performance backbone

Multi machine LAN office artifact rustdesk use push!!!

Build a simple website by yourself

How to back up all data on Apple mobile phone in 2 steps (free)

在命令行登录mysql数据库以及查看版本号

干货丨微服务架构是什么?有哪些优点和不足?

Libuv library overview and comparison of libevent, libev and libuv (Reprint)

MySQL review materials (additional) case when
随机推荐
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
IDEA修改jvm内存
直播预约|AWS Data Everywhere 系列活动
JSX的基本使用
Ask the handler about the memory leak scenario in the interview. Don't just know static internal classes & weak references!
源代码防泄露技术种类浅析
【FPGA+sin】基于DDS(直接数字合成)的正弦信号发生器模块FPGA实现
不使用union实现Mysql 列转行
SQL database stored procedure writing method
【C语言】解决 “address of stack memory associated with local variable ‘num‘ returned”
String不同创建方式的区别
欧拉开源社区第二届理事会第二次会议召开,新华三、超聚变和龙芯中科成为理事会成员单位
Blue Bridge Cup ruler method
Analysis of moudo Network Library
[fpga+sin] FPGA implementation of sinusoidal signal generator module based on DDS (direct digital synthesis)
技术:如何设计zkVM电路
为什么说测试岗位是巨坑?8年测试人告诉你千万别上当
Is the increased life insurance off the shelf? What additional life insurance products are available now?
logstash启动过慢甚至卡死
Qtableview gets all currently selected cells