PAT b 1018 Hammer and scissors cloth (C + + edition)

Source: Internet
Author: User

1018. Hammer and Scissors cloth (20) time limit MS Memory limit 65536 KB code length limit 8000 B procedure StandardAuthor Chen, Yue

Everyone should play "Hammer and Scissors Cloth" game: two people at the same time give gestures, the rule of victory:

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 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 format:

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 Sample:
10C JJ BC bb bb cc cc BJ BB CJ J
Sample output:
5 3 3 5B B


Idea: Compare winning and losing with ACS code difference

1 //1018.cpp: Defines the entry point of the console application. 2 //3 4#include"stdafx.h"5#include <iostream>6#include <typeinfo>7 8 using namespacestd;9 Ten intWin =0, lose =0;//Count the number of wins and losses One intx_times[3] = {0}, y_times[3] = {0};//Count the number of wins for X and y A  - //function Declaration - voidJudgeCharXCharY);//comparison function the voidShowintN);//Print function - intGet_max (intA[]);//The subscript of the maximum value is obtained -  - intMain () + { -     CharX, Y; +     intN; A  atCIN >>N; -  -      for(inti =0; i < N; ++i) -     { -CIN >> X >>Y; -  in judge (X, Y); -     } to  + Show (N); -  the     return 0; * } $ Panax Notoginseng //comparison function - voidJudgeCharXCharY) the { +     //Compare The difference between the letters between two people to win or lose A     Switch(static_cast<int> (X-Y)) the     { +      Case-1://B C -++win; $++x_times[0]; $          Break; -      Case-8://B J -++lose; the++y_times[2]; -          Break;Wuyi      Case 1://C B the++lose; -++y_times[0]; Wu          Break; -      Case-7://C J About++win; $++x_times[1]; -          Break; -      Case 8://J B -++win; A++x_times[2]; +          Break; the      Case 7://J C -++lose; $++y_times[1]; the     default://Equal the          Break; the     } the } -  in //Print function the voidShowintN) the { About     intMax =0, I; the     Charresult[3] = {'B','C','J' }; the  thecout << Win <<" "<< N-win-lose <<" "<< lose <<Endl +<< lose <<" "<< N-win-lose <<" "<< win <<Endl -<< Result[get_max (x_times)] <<" " the<< Result[get_max (y_times)] <<Endl;Bayi } the  the //The subscript of the maximum value is obtained - intGet_max (inttimes[]) - { the     intI, max=0; the  the      for(i =1; I <3; i++) the         if(Times[max] <Times[i]) -Max =i; the  the     returnMax; the}

PAT b 1018 Hammer and scissors cloth (C + + edition)

Related Article

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.