原题链接
最近在学c++
自己敲的,实现的有些麻烦,尤其是输出“获胜次数最多的手势”部分,等后续回来再改进。
对代码有疑问的,欢迎交流评论。
#include//20/20 using namespace std; int as = 0, ap = 0, af = 0; int b1 = 0, c1 = 0, j1 = 0; int b2 = 0, c2 = 0, j2 = 0; int check(char a, char b) { if (a == b) ap++; else if (a == 'C' && b == 'J') { c1++; as++; } else if (a == 'C' && b == 'B') { b2++; af++; } else if (a == 'J' && b == 'C') { c2++; af++; } else if (a == 'J' && b == 'B') { j1++; as++; } else if (a == 'B' && b == 'J') { af++; j2++; } else if (a == 'B' && b == 'C') { as++; b1++; } return 0; } int main() { int N; char a, b; char tab; cin >> N; while (N > 0) { cin >> a >> b; // cout << ':' << a << ':' << b << endl; check(a, b); N--; } cout << as << ' ' << ap << ' ' << af << endl; cout << af << ' ' << ap << ' ' << as << endl; if (b1 >= c1 && b1 >= j1) cout << "B "; else if (c1 >= j1) cout << "C "; else cout << "J "; if (b2 >= c2 && b2 >= j2) cout << "B"; else if (c2 >= j2) cout << "C"; else cout << "J"; // system("pause"); return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)