Hammer and scissors cloth

Source: Internet
Author: User


Title Description
We should all play "Hammer and Scissors Cloth" game: now give two people's record of confrontation, please count the wins, flat, negative times, and give the two sides what gesture of the greatest odds.


Input Description:
Enter line 1th to give the positive integer n (<=105), that 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 Description:
Output 1th, 2 respectively give a, B wins, 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.


Input Example:
10C JJ BC bb bb cc cc BJ BB CJ J


Output Example:
5 3 3 5B B
Reference Code:
#include <stdio.h> #include <stdlib.h> #define &NBSP;MAX (a,b,c)   (a>=b&&a>=c)? ' B ':(b>=c)? ' C ': ' J ' Int comp (char a,char b) {    if (a==b)        return 0;    else if (a== ' B ' &&b== ' C ')        return 1;    else if (a== ' C ' &&b== ' J ')        return 1;    else if (a== ' J ' &&b== ' B ')        return 1;    else       return -1;} Int main () {    int num,a_count_b=0,a_count_c=0,a_count_j=0,b_count_b=0,b_count_c =0,B_COUNT_J=0,WIN_COUNT=0,LOSE_COUNT=0;&NBSP;&NBSP;&NBSP;&NBSP;SCANF ("%d", &num);     Char game[num][2];    int i,flag;    for (i=0;i<num;i++) {        getchar (); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;SCANF ("%c %c", &game[i][0], &AMP;GAME[I][1]);     }    for (i=0;i<num;i++) {         flag=comp (game[i][0],game[i][1]);         if (flag>0) {            win_count++;             if (game[i][0]== ' B ')                A_count_B++;             else if (game[i][0]== ' C ')                A_count_C++;             else              a_ count_j++;         }else if (flag<0) {             lose_count++;            if (Game[i][1] = = ' B ')               B_count_B++;             else if (game[i][1]== ' C ')                B_count_C++;             else               B_count_J++;        }     }    printf ("%d %d %d\n", Win_count,num-win_count-lose_count,lose_count);     printf ("%d %d %d\n", Lose_count,num-win_count-lose_count,win_count);     printf ("%C %c\n ", Max (A_count_b,a_count_c,a_count_j), Max (B_count_b,b_count_c,b_count_j));     return 0;}

Original title Link: https://www.nowcoder.com/pat/6/problem/4044

Hammer and scissors cloth

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.