PAT_Basic 1018
2016-03-08 16:35
155 查看
/* 现给出两人的交锋记录,请统计双方的胜、平、负次数,并且给出双方分别出什么手势的胜算最大。 输入格式: 输入第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 <string> #include <vector> #include <iostream> using namespace std; int trans(char a){ if (a == 'C') return 0; else if (a == 'J') return 1; else if (a == 'B') return 2; else return -1; } char trans(int a){ if (a == 0) return 'C'; else if (a == 1) return 'J'; else return 'B'; } int cmp(char a, char b){ string tmp = {}; tmp.push_back(a); tmp.push_back(b); if ((tmp == "CJ") || (tmp 4000 == "JB") || (tmp == "BC")) return 1; else if (a == b) return 0; else return -1; } char max(int c,int j,int b){ int tmp; tmp = (c >= j) ? c : j; tmp = (b >= tmp) ? b : tmp; return trans(tmp); } void main(){ int N; cin >> N; char **all; all = (char**)malloc(sizeof(char*)*N); all[0] = (char*)malloc(sizeof(char)* N * 2); for (int i = 1; i < N; i++) all[i] = all[i - 1] + 2; int bf[2][3] = { 0 }; int ss[2][3] = { 0 }; for (int i = 0; i < N; i++){ cin >> all[i][0] >> all[i][1]; int ans =cmp(all[i][0], all[i][1]); switch (ans){ case -1: bf[0][2]++; bf[1][0]++; ss[1][trans(all[i][1])]++; break; case 0: bf[0][1]++; bf[1][1]++; break; case 1: bf[0][0]++; bf[1][2]++; ss[0][trans(all[i][0])]++; break; default:break; } } cout << bf[0][0] << " " << bf[0][1] << " " << bf[0][2] << endl; cout << bf[1][0] << " " << bf[1][1] << " " << bf[1][2] << endl; for (int i = 0; i < 2; i++){ cout << max(ss[i][0], ss[i][1], ss[i][2]) << " "; } system("pause"); }
A little boring
相关文章推荐
- 一些杂记
- STL find_if应用及其他
- Android图片高斯模糊的一些方法
- 二进制文件的读写
- netty
- spring spring-mvc mybatis jetty 的pom.xml依赖配置完整版
- 服务器发布MVC常见问题解决方案
- Eratosthes algrithm 求素数
- hdoj 5093 Battle ships 【二分图最大匹配】
- ubuntu用户添加adduser, useradd
- 【POJ2135】Farm Tour(最小费用最大流)
- 表-Stack栈
- Exynos4412 文件系统制作(二)—— 文件系统简介
- android viewpage用法及适配器
- 2 Javascript 存储数据
- Unsharp Mask(USM)锐化算法的的原理及其实现
- javascript动画
- ionic项目的一些简单操作
- 用Android Studio对应用签名打包
- Windows找不到文件’C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools\Computer Mana