1018 锤子剪刀布 (20 分)

//自己写的很长,这是参考的网上以为大牛的;
#include <iostream> #include <string> using namespace std; int main() { int n, y, wina = 0, winb = 0, a[3] = {0}, b[3] = {0};; char s, t; cin >> n; y = n; while (n--) { cin >> s >> t; if (s == 'B' && t == 'C') { wina++; a[0]++; } else if (s == 'C' && t == 'J') { wina++; a[1]++; } else if (s == 'J' && t == 'B') { wina++; a[2]++; } else if (s == 'C' && t == 'B') { winb++; b[0]++; } else if (s == 'J' && t == 'C') { winb++; b[1]++; } else if (s == 'B' && t == 'J') { winb++; b[2]++; } } cout << wina << ' ' << y - wina - winb << ' ' << winb << endl << winb << ' ' << y - wina - winb << ' ' << wina << endl; int maxjia = a[0] >= a[1] ? 0 : 1; // 不能忘了有相等的情况;比较顺序也很重要; maxjia = a[maxjia] >= a[2] ? maxjia : 2; int maxyi = b[0] >= b[1] ? 0 : 1; maxyi = b[maxyi] >= b[2] ? maxyi : 2; char str[4] = {"BCJ"}; cout << str[maxjia] << ' ' << str[maxyi] << endl; return 0; }
原文地址:https://www.cnblogs.com/Hk456/p/10750934.html