Now give a record of the confrontation between two people, please count the wins, flat, negative number of both sides, and give the two sides what gesture of the greatest odds.
Input format:
Enter the 1th line to give the positive integer n (<=105), which is the number of times the two sides clash. Then n lines, each row gives the information of a confrontation, that is, a, b both sides of the gesture given at the same time. C for "Hammer", J for "Scissors", B for "cloth", 1th letter for party A, 2nd for party B, 1 spaces in the middle.
Output format:
The output 1th, 2 respectively gives a, b of the win, flat, negative times, the number between 1 spaces separated. The 3rd line gives two letters, representing the most winning gestures of A and b, with 1 spaces in the middle. If the solution is not unique, the solution with the smallest alphabetic order is output.
#include <stdio.h> #include <stdlib.h> #include <iostream>using namespace Std;int change (char a) {Swit CH (a) {case ' B ': return 0; Case ' C ': return 1; Case ' J ': return 2; }}int Main () {int num; scanf ("%d", &num); Char hand[3]={' B ', ' C ', ' J '}; Char First,second; int k1,k2; int times[3]={0},sort1[3]={0},sort2[3]={0}; for (int i=0;i<num;i++) {cin>>first; cin>>second; K1=change (first); K2=change (second); if ((k1+1)%3==k2) {times[0]++; sort1[k1]++; } else if (K1==K2) {times[1]++; } else if ((k2+1)%3==k1) {times[2]++; sort2[k2]++; }} printf ("%d%d%d\n", times[0],times[1],times[2]); printf ("%d%d%d\n", times[2],times[1],times[0]); Intj1=0,j2=0; for (int i=0;i<3;i++) {if (sort1[i]>sort1[j1]) j1=i; if (sort2[i]>sort2[j2]) j2=i; } printf ("%c%c\n", Hand[j1],hand[j2]); System ("pause"); return 0; }
1018. Hammer and scissors cloth