Everyone should be able to play the game of "hammer, scissors and cloth": two people give gestures at the same time, and the winning and losing rules are as shown in the figure:
Here is the record of the fight between the two. Please count the number of wins, evenings and defeats of both sides, and give the most successful hand gestures of both sides.
Input format:
Enter the first line to give a positive integer N (< 10 5), that is, the number of times the two sides are fighting. Then line N, each line gives the information of a confrontation, that is, the gestures given by both parties at the same time. C represents "hammer", J represents "scissors", B represents "cloth", the first letter represents Party A, the second represents Party B, and there is a space in the middle.
Output format:
The first and second lines of the output show the win, level and negative times of a and B respectively, and the numbers are separated by a space. The third line gives two letters, representing the gesture with the most winning times of a and B respectively, with a space in the middle. If the solution is not unique, the solution with the smallest alphabetical order is output.
Input example:
10 C J J B C B B B B C C C C B J B B C J J
Output example:
5 3 2 2 3 5 B B
import java.util.Scanner; public class Main { static String bidui(int a[]) { if(a[0]>a[1]&&a[0]>a[2]) { return "B" ;} else if(a[1]>a[0]&&a[1]>a[2]) { return"C";} else if(a[2]>a[0]&&a[2]>a[1]){ return"J";} else if(a[0]==a[1]&&a[0]>a[2]){ return"B";} else if(a[0]>a[1]&&a[0]==a[2]){ return"B";} else if(a[1]>a[0]&&a[1]==a[2]){ return"C";} else if(a[0]==a[1]&&a[0]==a[2]){ return"B";} return null; } public static void main(String[] args) { // Method stubs generated automatically by TODO Scanner sc = new Scanner(System.in); int a=sc.nextInt();sc.nextLine(); char ar[][]=new char [a][2]; int j[]=new int [3]; int jh[]=new int [3]; int y[]=new int [3]; int yh[]=new int [3]; for(int i=0;i<ar.length;i++) { String aq[]=sc.nextLine().split(" "); ar[i][0]=aq[0].charAt(0); ar[i][1]=aq[1].charAt(0); if(ar[i][0]==ar[i][1]) { j[1]++; y[1]++; } else if(ar[i][0]=='C'&&ar[i][1]=='J'||ar[i][0]=='J'&&ar[i][1]=='B'||ar[i][0]=='B'&&ar[i][1]=='C' ){ j[0]++; y[2]++; if(ar[i][0]=='B')jh[0]++; else if(ar[i][0]=='C')jh[1]++; else if(ar[i][0]=='J')jh[2]++; } else if(ar[i][0]=='J'&&ar[i][1]=='C'||ar[i][0]=='B'&&ar[i][1]=='J'||ar[i][0]=='C'&&ar[i][1]=='B' ){ y[0]++; j[2]++; if(ar[i][1]=='B')yh[0]++; else if(ar[i][1]=='C')yh[1]++; else if(ar[i][1]=='J')yh[2]++; } } System.out.println(j[0]+" "+j[1]+" "+j[2]); System.out.println(y[0]+" "+y[1]+" "+y[2]); System.out.println(bidui(jh)+" "+bidui(yh)); } }
Thought summary here I used two arrays to store the scores of a and B respectively, and then used two arrays to store the corresponding punches of a and B when they won, and then printed out the scores of a and B, and then used a method to compare what happened at the time of winning to process the other two arrays at most. What should be noted here is that when there are the same number of punches winning types As long as the output letter order is the smallest, for example, the number of hammer and scissors cloth is the same, then output B this is good