首页 > 试题广场 >

锤子剪刀布 (20)

[编程题]锤子剪刀布 (20)
  • 热度指数:31488 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
大家应该都会玩“锤子剪刀布”的游戏:

现给出两人的交锋记录,请统计双方的胜、平、负次数,并且给出双方分别出什么手势的胜算最大。

输入描述:
输入第1行给出正整数N(<=105),即双方交锋的次数。随后N行,每行给出一次交锋的信息,即甲、乙双方同时给出的的手势。C代表“锤子”、J代表“剪刀”、B代
表“布”,第1个字母代表甲方,第2个代表乙方,中间有1个空格。


输出描述:
输出第1、2行分别给出甲、乙的胜、平、负次数,数字间以1个空格分隔。第3行给出两个字母,分别代表甲、乙获胜次数最多的手势,中间有1个空格。如果解不唯
一,则输出按字母序最小的解。
示例1

输入

10<br/>C J<br/>J B<br/>C B<br/>B B<br/>B C<br/>C C<br/>C B<br/>J B<br/>B C<br/>J J

输出

5 3 2<br/>2 3 5<br/>B B
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        int count = 0;
        int[] bifen = new int[3];

        char[] A = new char[num];
        char[] B = new char[num];

        int A_C = 0, A_J = 0, A_B =0, B_C = 0, B_J = 0, B_B =0;
        while (num-- > 0){
            A[count] = scanner.next().charAt(0);
            B[count] = scanner.next().charAt(0);
            if (A[count] == B[count]){
                bifen[1]++;
            }else if (A[count] == 'C' && B[count] == 'J'){
                bifen[0]++;
                A_C++;
            }else if (A[count] == 'C' && B[count] == 'B'){
                bifen[2]++;
                B_B++;
            }else if (A[count] == 'J' && B[count] == 'C'){
                bifen[2]++;
                B_C++;
            }else if (A[count] == 'J' && B[count] == 'B'){
                bifen[0]++;
                A_J++;
            }else if (A[count] == 'B' && B[count] == 'C'){
                bifen[0]++;
                A_B++;
            }else if(A[count] == 'B' && B[count] == 'J'){
                bifen[2]++;
                B_J++;
            }

        }
        System.out.println(bifen[0]+ " " + bifen[1] + " " + bifen[2]);
        System.out.println(bifen[2]+ " " + bifen[1] + " " + bifen[0]);
        if (A_C == A_B && A_C == A_J || A_B >= A_C && A_B >= A_J)
            System.out.print("B ");
        else if (A_C >= A_B && A_C >= A_J)
            System.out.print("C ");
        else
            System.out.print("J ");

        if (B_C == B_B && B_C == A_J || B_B >= B_C && B_B >= B_J)
            System.out.print("B");
        else if (B_C >= B_B && B_C >= B_J)
            System.out.print("C");
        else
            System.out.print("J");
    }
}

发表于 2019-07-01 21:14:54 回复(0)
更多回答
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            int v = 0;
            int f = 0;
            Map<Character, Integer> mapA = new TreeMap<>();
            Map<Character, Integer> mapB = new TreeMap<>();
            for (int i = 0; i < n; i++) {
                char a = sc.next().charAt(0);
                char b = sc.next().charAt(0);
                int re = match(a, b);
                if (re == 1) {
                    v++;
                    if (mapA.containsKey(a)) {
                        mapA.put(a, mapA.get(a) + 1);
                    } else {
                        mapA.put(a, 1);
                    }

                } else if (re == -1) {
                    f++;
                    if (mapB.containsKey(b)) {
                        mapB.put(b, mapB.get(b) + 1);
                    } else {
                        mapB.put(b, 1);
                    }
                }
            }
            System.out.println(v + " " + (n - v - f) + " " + f);
            System.out.println(f + " " + (n - v - f) + " " + v);
            int max = 0;
            for (Map.Entry<Character, Integer> m : mapA.entrySet()) {
                if (m.getValue() > max) {
                    max = m.getValue();
                }
            }
            if (max == 0) {
                System.out.print("B");
            } else {
                for (Map.Entry<Character, Integer> m : mapA.entrySet()) {
                    if (m.getValue() == max) {
                        System.out.print(m.getKey());
                        break;
                    }
                }
            }
            max = 0;
            System.out.print(" ");
            for (Map.Entry<Character, Integer> m : mapB.entrySet()) {
                if (m.getValue() > max) {
                    max = m.getValue();
                }
            }
            if (max == 0) {
                System.out.print("B");
            } else {
                for (Map.Entry<Character, Integer> m : mapB.entrySet()) {
                    if (m.getValue() == max) {
                        System.out.print(m.getKey());
                        break;
                    }
                }
            }
        }
    }

    public static int match(char a, char b) {
        if (a == b) {
            return 0;
        } else if ((a == 'C' && b == 'J') || (a == 'J' && b == 'B') || (a == 'B' && b == 'C')) {
            return 1;
        } else {
            return -1;
        }
    }
}

编辑于 2020-03-10 21:27:53 回复(1)

python solution

win, lose, tie = 0, 0, 0 #甲的勝、負、平次數
Jia, Yi = [0, 0, 0], [0, 0, 0]  # B C J  count #甲乙勝時出的手勢記錄
num = int(input())
for i in range(num):
    string = input()
    if string == "C J":
        win += 1
        Jia[1] += 1
    elif string == "J C":
        lose += 1
        Yi[1] += 1
    elif string == "C B":
        lose += 1
        Yi[0] += 1
    elif string == "B C":
        win += 1
        Jia[0] += 2
    elif string == "B J":
        lose += 1
        Yi[2] += 1
    elif string == "J B":
        win += 1
        Jia[2] += 1
    else:  # there is a tie
        tie += 1
print(win, tie, lose)
print(lose, tie, win)
print("BCJ"[Jia.index(max(Jia))], "BCJ"[Yi.index(max(Yi))])
发表于 2017-11-17 14:22:40 回复(0)
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
     
    private static int getMaxIndex(int[] arr) {
         
        int maximumIndex = 0;
         
        for(int i = 0; i < arr.length; i++) {
            if(arr[i] > arr[maximumIndex]) {
                maximumIndex = i;
            }
        }
         
        return maximumIndex;
    }
     
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         
        int N = Integer.parseInt(br.readLine());
         
        final String[] gesture = {"B" ,"C", "J"};
         
        int[] ATime = {0, 0, 0};
        int[] BTime = {0, 0, 0};
         
        int[] AWinGesture = {0, 0, 0};
        int[] BWinGesture = {0, 0, 0};
         
        String[] game;
         
        for(int i = 0; i < N; i++) {
            game = br.readLine().split(" ");
             
            switch(game[0]) {
                case "C" :{
                    switch (game[1]) {
                        case "C":{
                            ATime[1]++;
                            BTime[1]++;
                            break;
                        }
                        case "J":{
                            ATime[0]++;
                            BTime[2]++;
                            AWinGesture[1]++;
                            break;
                        }
                        case "B":{
                            ATime[2]++;
                            BTime[0]++;
                            BWinGesture[0]++;
                            break;
                        }
                        default:break;
                    }
                    break;
                }
                case "J" :{
                    switch (game[1]) {
                        case "C":{
                            ATime[2]++;
                            BTime[0]++;
                            BWinGesture[1]++;
                            break;
                        }
                        case "J":{
                            ATime[1]++;
                            BTime[1]++;
                            break;
                        }
                        case "B":{
                            ATime[0]++;
                            BTime[2]++;
                            AWinGesture[2]++;
                            break;
                        }
                        default:break;
                    }
                    break;
                }
                case "B" :{
                    switch (game[1]) {
                        case "C":{
                            ATime[0]++;
                            BTime[2]++;
                            AWinGesture[0]++;
                            break;
                        }
                        case "J":{
                            ATime[2]++;
                            BTime[0]++;
                            BWinGesture[2]++;
                            break;
                        }
                        case "B":{
                            ATime[1]++;
                            BTime[1]++;
                            break;
                        }
                        default:break;
                    }
                    break;
                }
                default : break;
            }
        }
         
        System.out.println(ATime[0] + " " + ATime[1] + " " + ATime[2]);
        System.out.println(BTime[0] + " " + BTime[1] + " " + BTime[2]);
        System.out.println(gesture[getMaxIndex(AWinGesture)] + " " + gesture[getMaxIndex(BWinGesture)]);
    }
}

发表于 2017-11-15 18:07:54 回复(0)
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int[] js = new int[3];
		int jf = 0;
		int[] ys = new int[3];
		int yf = 0;
		int p = 0;
		while(N--!=0){
			int j = convert(in.next());
			int y = convert(in.next());
			if(j==y)
				p++;
			else if(judge(j, y)){
				//甲赢
				js[j]++;
				yf++;
			}else{
				ys[y]++;
				jf++;
			}
		}
		System.out.println(yf+" "+p+" "+jf);
		System.out.println(jf+" "+p+" "+yf);
		System.out.println(getResult(js)+" "+getResult(ys));
	}
	
	private static int convert(String s){
		if(s.equals("B"))
			return 0;
		if(s.equals("C"))
			return 1;
		return 2;// J
	}
	private static boolean judge(int j,int y){
		if(j==2&&y==0)
			return true;
		else if(j>y)
			return false;
		return true;
	}
	private static String getResult(int[] a){
		int max = a[0];
		int index = 0;
		for(int i = 1;i<a.length;i++){
			if(a[i]>max){
				max = a[i];
				index = i;
			}
		}
		return index==0?"B":index==1?"C":"J";
	}
}

发表于 2016-06-08 21:54:32 回复(0)
//记为ab两人 a胜利的情况为:CJ、BC、JB。b胜利的情况为:JC、CB、BJ。
//根据两人胜利的情况分别统计出两人胜利的次数。平局次数 = 总场数-a胜利-b胜利。
// 用LinkedHashMap记录下ab胜利使用次数的情况。输出胜利次数最多使用情况,如果相同按字母顺序输出。
//会有三种极端情况
//情况一二:ab两人中一人全胜。举例:若a全胜且使用次数最多为C则此时b虽然全输,但是应该输出B
//因为题目描述为:双方分别出什么手势胜算最大。
//情况三:ab全平。此时胜算最大无输出,(牛客应该没有情况三的用例)
import java.util.*;

public class Main {
    private static int winA = 0;
    private static int winB = 0;
    private static HashMap<Character,Integer> A = new LinkedHashMap<Character,Integer>();
    private static HashMap<Character,Integer> B = new LinkedHashMap<Character,Integer>();
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()) {
            int n = sc.nextInt();
            int count = n;
            sc.nextLine();
            while(count-- > 0) {
                String[] str = sc.nextLine().split(" ");
                StringBuffer sb = new StringBuffer();
                for(String s : str) {
                    sb.append(s);
                }
                Cjb(sb.toString());
            }
            int peace = n-winA-winB;
            System.out.println(winA+" "+peace+" "+winB);
            System.out.println(winB+" "+peace+" "+winA);
            if(A.size() != 0 && B.size() != 0) {
                System.out.println(Mvp(A)+" "+Mvp(B));  
            }
            if(A.size() == 0 && B.size() != 0) {
               char a = (Mvp(B) == 'B') ? 'J' :((Mvp(B) == 'C') ? 'B' : 'C');
                System.out.println(a+" "+Mvp(B));
            }
            if(A.size() != 0 && B.size() == 0) {
                char b = (Mvp(A) == 'B') ? 'J' :((Mvp(A) == 'C') ? 'B' : 'C');
                System.out.println(Mvp(A)+" "+b);
            }
        }
    }

    private static char Mvp(HashMap<Character,Integer> map) {
        Set<Character> set = map.keySet();
        int tmp = 0;
        char ret = 'Z';
        for(char c : set) {
            if(tmp <= map.get(c)) {
                tmp = map.get(c);
                if(ret > c) {
                    ret = c;
                }
            }
        }
        return ret;
    }

    private static void Cjb(String s) {
        if(s.equals("CJ") || s.equals("JB") || s.equals("BC")) {
            winA++;
            A.put(s.charAt(0),A.containsKey(s.charAt(0)) ? A.get(s.charAt(0))+1 : 1);
        }
        if(s.equals("JC") || s.equals("BJ") || s.equals("CB")) {
            winB++;
            B.put(s.charAt(1),B.containsKey(s.charAt(1)) ? B.get(s.charAt(1))+1 : 1);
        }
    }
}

发表于 2020-04-08 15:01:56 回复(0)
和大家的思路差不多的亚子,容易理解的通俗解法
#include <iostream>
using namespace std;

/*

C > J 
J > B
B > C

B > C > J > B

*/

int main(int argc, char** argv) {
	
	int num;
	// 0:胜,	1:平,	2:负,	3:B,	4:C,	5:J  
	int jarr[6] = {0}, yarr[6] = {0};	
	char ja, yi;
	
	cin >> num;
	while(num--){			// 求获胜次数获胜字母的次数 
		cin >> ja >> yi;
		if(ja == 'B' && yi == 'C'){
			jarr[0]++;
			yarr[2]++;
			jarr[3]++; 
		}else if(ja == 'C' && yi == 'B'){
			jarr[2]++;
			yarr[0]++;
			yarr[3]++;
		}else if(ja == 'J' && yi == 'B'){
			jarr[0]++;
			yarr[2]++;
			jarr[5]++;
		}else if(ja == 'B' && yi == 'J'){
			jarr[2]++;
			yarr[0]++;
			yarr[5]++;
		}else if(ja == 'C' && yi == 'J'){
			jarr[0]++;
			yarr[2]++;
			jarr[4]++;
		}else if(ja == 'J' && yi == 'C'){
			jarr[2]++;
			yarr[0]++;
			yarr[4]++;
		}else{
			jarr[1]++;
			yarr[1]++;
		}
	}
	
	ja = jarr[4] >= jarr[5] ? 'C' : 'J';
	ja = jarr[3] >= jarr[4] ? 'B' : ja;
	
	yi = yarr[4] >= yarr[5] ? 'C' : 'J';
	yi = yarr[3] >= yarr[4] ? 'B' : yi;
	
	for(int i = 0; i < 3; i++){
		cout << jarr[i];
		if(i!=2) cout << " ";
	}
	cout << endl;
	for(int i = 0; i < 3; i++){
		cout << yarr[i];
		if(i!=2) cout << " ";
	}
	cout << endl;
	cout << ja << " " << yi;
	
	return 0;
}


发表于 2020-02-27 21:20:39 回复(0)
#include<iostream>
#
include<string>
using namespace std;
struct node{
    char x;
    char y;
};
int main(){
    int n;
    cin>>n;
    node s[106];
    int sjcount=0,fjcount=0,p=0;
    string strj,stry;
    for(int i=0;i<n;i++){
        cin>>s[i].x>>s[i].y;
        if(s[i].x==s[i].y)p++;
        else {
            if(s[i].x=='C'){
                if(s[i].y=='J'){
                    sjcount++;
                    strj.push_back('C');
                }
                else{
                    fjcount++;
                    stry.push_back('B');
                }
        }
            else if(s[i].x=='B'){
                if(s[i].y=='C'){
                    sjcount++;
                    strj.push_back('B');
                }
                else{
                    fjcount++;
                    stry.push_back('J');
                }
            }
            else if(s[i].x=='J'){
                if(s[i].y=='B'){
                    sjcount++;
                    strj.push_back('J');
                }
                else{
                    fjcount++;
                    stry.push_back('C');
                }
            }
        }
    }
    int countjJ=0,countjB=0,countjC=0,countyJ=0,countyB=0,countyC=0;
    for(int i=0;i<strj.length();i++){
        if(strj[i]=='J')countjJ++;
        else if(strj[i]=='B')countjB++;
        else countjC++;
    }
    for(int i=0;i<stry.length();i++){
        if(stry[i]=='J')countyJ++;
        else if(stry[i]=='B')countyB++;
        else countyC++;
    }
    cout<<sjcount<<" "<<p<<" "<<fjcount<<endl;
    cout<<fjcount<<" "<<p<<" "<<sjcount<<endl;
    if(countjB>=countjJ&&countjB>=countjC)cout<<"B"<<" ";
    else if(countjC>countjB&&countjC>=countjJ)cout<<"C"<<" ";
    else cout<<"J"<<" ";
    if(countyB>=countyJ&&countyB>=countyC)cout<<"B";
    else if(countyC>countyB&&countyC>=countyJ)cout<<"C";
    else cout<<"J";
    return 0;
}
发表于 2020-02-23 12:52:16 回复(0)
//锤子剪刀布
int main()
{
	int n;
	cin >> n;
	int p1 = 0, p2 = 0, p3 = 0;
	int q1 = 0, q2 = 0, q3 = 0;
	int equ = 0;
	for (int i = 0; i < n; i++)
	{
		char a, b;
		cin >> a >> b;
		if (a == 'C'&&b == 'J')      p1++;
		else if (a == 'C'&&b == 'B') q3++;
		else if (a == 'C'&&b == 'C') equ++;
		else if (a == 'J'&&b == 'J') equ++;
		else if (a == 'J'&&b == 'B') p2++;
		else if (a == 'J'&&b == 'C') q1++;

		else if (a == 'B'&&b == 'J') q2++;
		else if (a == 'B'&&b == 'B') equ++;
		else if (a == 'B'&&b == 'C') p3++;
	}
	int pmax = p3, qmax = q3;
	if (pmax < p1) pmax = p2;
	if (pmax < p2) pmax = p1;

	if (qmax < q1) qmax = q2;
	if (qmax < q2) qmax = q1;
	cout << p1 + p2 + p3 << ' ' << equ << ' ' << q1 + q2 + q3 << endl;
	cout << q1 + q2 + q3 << ' ' << equ << ' ' << p1 + p2 + p3 << endl;
	if (pmax == p3)cout << 'B';
	else if (pmax == p1)cout << 'C';
	else cout << 'J';
	cout << ' ';
	if (qmax == q3)cout << 'B';
	else if (qmax == q1)cout << 'C';
	else cout << 'J';
	cout << endl;
	return 0;
}

发表于 2019-08-17 16:54:02 回复(0)
/*
甲胜利有3种情况
C J
J B
B C
乙胜利反之
J C
B J
C B
此题在输入时判断次数,则不需要开数组
求出甲胜利、平局的次数和甲、乙出锤、剪、布胜利的次数即可 

*/

#include<iostream>
using namespace std;
char jia,yi;    
int times;
int jiaWin=0,Ping=0;
int jiaChui=0,jiaBu=0,jiaJian=0;
int yiChui=0,yiBu=0,yiJian=0;
int i;
int main(){
    cin>>times;
    for(i=0;i<times;i++){
        cin>>jia>>yi;
        if(jia=='C'&&yi=='J'){
            jiaWin++;
            jiaChui++;
        }else if(jia=='J'&&yi=='B'){
            jiaWin++;
            jiaJian++;
        }else if(jia=='B'&&yi=='C'){
            jiaWin++;
            jiaBu++;
        }else if(jia==yi)Ping++;        
        else if(yi=='C'&&jia=='J')yiChui++;
        else if(yi=='J'&&jia=='B')yiJian++;
        else if(yi=='B'&&jia=='C')yiBu++;
    }
    cout<<jiaWin<<" "<<Ping<<" "<<times-Ping-jiaWin<<endl
        <<times-Ping-jiaWin<<" "<<Ping<<" "<<jiaWin<<endl;
        
    if(jiaBu>=jiaChui&&jiaBu>=jiaJian)cout<<"B ";
    else if(jiaChui>=jiaJian&&jiaChui>jiaBu)cout<<"C ";
    else cout<<"J ";
    if(yiBu>=yiChui&&yiBu>=yiJian)cout<<"B";
    else if(yiChui>=yiJian&&yiChui>yiBu)cout<<"C";
    else cout<<"J";
    
    return 0;
}

编辑于 2019-07-24 12:36:15 回复(0)
#include <iostream>

using namespace std;
struct Caiquan
{
    int jia_win=0;
    int jia_lose=0;
    int tie=0;
    int yi_win=0;
    int yi_lose=0;
    int jia_J=0;
    int jia_C=0;
    int jia_B=0;
    int yi_J=0;
    int yi_C=0;
    int yi_B=0;
}caiquan;
int main()
{
    int N,i;
    char j,y;
    cin>>N;
    for(i=0;i<N;i++)
    {
        cin>>j;
        getchar();
        cin>>y;
        if((j=='J'&&y=='J')||(j=='C'&&y=='C')||(j=='B'&&y=='B'))
        {
            caiquan.tie+=1;
        }
        else if(j=='J'&&y=='B')
        {
            caiquan.jia_win+=1;
            caiquan.yi_lose+=1;
            caiquan.jia_J+=1;
        }
        else if(j=='C'&&y=='J')
        {
            caiquan.jia_win+=1;
            caiquan.yi_lose+=1;
            caiquan.jia_C+=1;
        }
        else if(j=='B'&&y=='C')
        {
            caiquan.jia_win+=1;
            caiquan.yi_lose+=1;
            caiquan.jia_B+=1;
        }
        else if(y=='J'&&j=='B')
        {
            caiquan.jia_lose+=1;
            caiquan.yi_win+=1;
            caiquan.yi_J+=1;
        }
        else if(y=='C'&&j=='J')
        {
            caiquan.jia_lose+=1;
            caiquan.yi_win+=1;
            caiquan.yi_C+=1;
        }
        else if(y=='B'&&j=='C')
        {
            caiquan.jia_lose+=1;
            caiquan.yi_win+=1;
            caiquan.yi_B+=1;
        }
    }
    cout<<caiquan.jia_win<<" "<<caiquan.tie<<" "<<caiquan.jia_lose<<endl;
    cout<<caiquan.yi_win<<" "<<caiquan.tie<<" "<<caiquan.yi_lose<<endl;
    if(caiquan.jia_B>=caiquan.jia_C&&caiquan.jia_B>=caiquan.jia_J)cout<<"B ";
    else if(caiquan.jia_C>caiquan.jia_B&&caiquan.jia_C>=caiquan.jia_J)cout<<"C ";
    else if(caiquan.jia_J>caiquan.jia_B&&caiquan.jia_J>caiquan.jia_C)cout<<"J ";
    if(caiquan.yi_B>=caiquan.yi_C&&caiquan.yi_B>=caiquan.yi_J)cout<<"B";
    else if(caiquan.yi_C>caiquan.yi_B&&caiquan.yi_C>=caiquan.yi_J)cout<<"C";
    else if(caiquan.yi_J>caiquan.yi_B&&caiquan.yi_J>caiquan.yi_C)cout<<"J";
}

发表于 2019-07-11 14:45:27 回复(0)
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. map<string,int>q1,q2;
  4. map<string,int>::iterator it;
  5. int main()
  6. {
  7.     int n;
  8.     cin>>n;
  9.     string s1,s2;
  10.     int a1,b1,c1;
  11.     int a2,b2,c2;
  12.     a1=a2=b1=b2=c1=c2=0;
  13.     for(int i=0; i<n; i++)
  14.     {
  15.         cin>>s1>>s2;
  16.         if(s1=="C"&&s2=="J"||s1=="J"&&s2=="B"||s1=="B"&&s2=="C")
  17.         {
  18.             a1++;
  19.             c2++;
  20.             q1[s1]++;
  21.         }
  22.         else if(s2=="C"&&s1=="J"||s2=="J"&&s1=="B"||s2=="B"&&s1=="C")
  23.         {
  24.             a2++;
  25.             c1++;
  26.             q2[s2]++;
  27.         }
  28.         else if(s1==s2)
  29.         {
  30.             b1++;
  31.             b2++;
  32.             q1[s1]++;
  33.             q2[s1]++;
  34.         }
  35.     }
  36.     printf("%d %d %d\n",a1,b1,c1);
  37.     printf("%d %d %d\n",a2,b2,c2);
  38.     int l,r;
  39.     string l1,r1;
  40.     l=r=0;
  41.     for(it=q1.begin(); it!=q1.end(); it++)
  42.     {
  43.         if(it->second>l)
  44.         {
  45.             l1=it->first;
  46.             l=it->second;
  47.         }
  48.     }
  49.     for(it=q2.begin(); it!=q2.end(); it++)
  50.     {
  51.         if(it->second>r)
  52.         {
  53.             r1=it->first;
  54.             r=it->second;
  55.         }
  56.     }
  57.     if(a1!=0&&a2==0)
  58.     {
  59.         if(l1=="C")
  60.             r1="B";
  61.         if(l1=="J")
  62.             r1="C";
  63.         if(l1=="B")
  64.             r1="J";
  65.     }
  66.     else if(a1==0&&a2!=0)
  67.     {
  68.         if(r1=="C")
  69.             l1="B";
  70.         if(r1=="J")
  71.             l1="C";
  72.         if(r1=="B")
  73.             l1="J";
  74.     }
  75.     cout<<l1<<" "<<r1<<endl;
  76.     return 0;
  77. }

编辑于 2018-12-13 23:46:02 回复(0)
#include<iostream>
using namespace std;

int main(){
    int times;
    while(cin>>times){
        char a, b;
        int awin = 0, bwin = 0, alose = 0, blose = 0, balance = 0;
        int  aJ = 0, aC = 0, aB = 0, bJ = 0, bC = 0, bB = 0;
        while(times--){
            cin>>a>>b;
            if((a=='J'&&b=='B')||(a=='B'&&b=='C')||(a=='C'&&b=='J'))
            {
                awin++;
                blose++;
                if(a=='J')
                {
                    aJ++;
                }
                else if(a=='B'){
                    aB++;
                }
                else{
                    aC++;
                }
            }
            else if(a==b)
            {
                balance++;
            }
            else{
                bwin++;
                alose++;
                if(b=='J')
                {
                    bJ++;
                }
                else if(b=='B'){
                    bB++;
                }
                else{
                    bC++;
                }
            }
            
        }
        cout<<awin<<" "<<balance<<" "<<alose<<endl;
        cout<<bwin<<" "<<balance<<" "<<blose<<endl;
        if(aJ>aB)
        {
            if(aB>=aC)
            cout<<'J'<<" ";
            else if(aJ==aC)
            cout<<'C'<<" ";
                    
        }
        else if(aJ>=aC)
        {
            cout<<'B'<<" ";
            
        }
        else
        {
            cout<<'C'<<" ";
        }
        if(bJ>bB)
        {
            if(bB>=bC)
            cout<<'J'<<endl;
            else if(bJ==bC)
            cout<<'C'<<endl;
                    
        }
        else if(bJ>=bC)
        {
            cout<<'B'<<endl;
            
        }
        else
        {
            cout<<'C'<<endl;
        }
    }
    return 0;


发表于 2018-08-10 19:13:32 回复(0)
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int m,i,j,s[80]={0},s1[80]={0},t=0,t1=0,t2=0,a[2][3]={0},max=0,max1=0,a1,b;
    char no,st;
    cin >> m;
    for(i = 0; i < m; i++)
    {
        cin >> no >>st;
        if(no - st == -7 || no - st == 8 || no - st == -1)
            {
                a[0][0]++;
                a[1][2]++;
                if(no - st == -7)s[no]++;
                if(no - st == 8)s[no]++;
                if(no - st == -1)s[no]++;
             }
             else if(no - st == 0)
                {
                    a[0][1]++;
                    a[1][1]++;
                }
                else
                    {
                        a[0][2]++;
                        a[1][0]++;
                        if(no - st == 7)s1[st]++;
                        if(no - st == -8)s1[st]++;
                        if(no - st == 1)s1[st]++;
             }
    }
    /*cout << s[66] << s[67] << s[74] << endl;
    cout << s1[66] << s1[67] <<s1[74] << endl;*/
        if(max < s[66]||max1 < s1[66]){
            if(max1 < s1[66]){max1=s1[66];b=66;}
            if(max < s[66]){max=s[66];a1=66;}}
        if(max < s[67]||max1 < s1[67]){
            if(max < s[67] ){max=s[67];t=1;a1=67;}
            if(max1 < s1[67]){max1=s1[67];t1=1;b=67;}}
        if((max < s[74]||max1 < s1[74])){
            if(t != 1 && max < s[74]){max=s[74];a1=74;}
            if(t1 != 1 && max1 < s1[74]){max1=s1[74];b=74;}}
    for(i = 0; i < 2; i++)
    {
        for(j = 0; j < 3; j++)
            {if(j != 2)cout << a[i][j] <<' ';
                else cout << a[i][j];
            }
            cout << endl;
    }
    if(a1==66)cout << 'B' << ' ';
    if(a1==67)cout << 'C' << ' ';
    if(a1==74)cout << 'J' << ' ';
    if(b==66)cout << 'B';
    if(b==67)cout << 'C';
    if(b==74)cout << 'J';
    return 0;
}



编辑于 2018-08-14 09:44:30 回复(0)
//
//  p_1008.cpp
//  PAT_basic_level
//
//  Created by 李嘉宁 on 2018/4/19.
//  Copyright © 2018年 李嘉宁. All rights reserved.
//
 
#include <iostream>
 
using namespace std;
 
intmain()
{
    ints = 0, p = 0, f = 0;
    intc1 = 0, j1 = 0, b1 = 0;
    intc2 = 0, j2 = 0, b2 = 0;
    intN = 0;
    charjia[105], yi[105];      // 考虑过二维数组
     
    cin >> N;
    for(inti = 0; i < N; i++)
    {
        cin >> jia[i] >> yi[i];
        if(jia[i] == 'C'&& yi[i] == 'J')      // 考虑过C\J\B 之间的规律
        {
            s++;
            c1++;
        }
        elseif(jia[i] == 'J'&& yi[i] == 'B')
        {
            s++;
            j1++;
        }
        elseif(jia[i] == 'B'&& yi[i] == 'C')
        {
            s++;
            b1++;
        }
        elseif((jia[i] == 'C'&& yi[i] == 'C') || (jia[i] == 'J'&& yi[i] == 'J') || (jia[i] == 'B'&& yi[i] == 'B'))
        {
            p++;
        }
        elseif(jia[i] == 'C'&& yi[i] == 'B')
        {
            f++;
            b2++;
        }
        elseif(jia[i] == 'J'&& yi[i] == 'C')
        {
            f++;
            c2++;
        }
        elseif(jia[i] == 'B'&& yi[i] == 'J')
        {
            f++;
            j2++;
        }
    }
    cout << s << ' '<< p << ' '<< f << endl;
    cout << f << ' '<< p << ' '<< s << endl;
     
    cout << ((((b1 >= c1) ? b1 : c1) >= j1) ? ((b1 >= c1) ? 'B': 'C') : 'J') << ' '<< ((((b2 >= c2) ? b2 : c2) >= j2) ? ((b2 >= c2) ? 'B': 'C') : 'J');
 
    return0;
}

发表于 2018-04-19 15:24:28 回复(0)
j_p = 0
j_s_c, j_s_j, j_s_b = 0, 0, 0
y_p = 0
y_s_c, y_s_j, y_s_b = 0, 0, 0


def most_win(b, c, j):
    if b == max(b, c, j):
        return 'B'
    elif c == max(b, c, j):
        return 'C'
    elif j == max(b, c, j):
        return 'J'


n = int(input())
for i in range(n):
    j, y = input().split()
    if j == y:
        j_p += 1  y_p += 1
    elif j == 'C' and y == 'J':
        j_s_c += 1
    elif j == 'J' and y == 'B':
        j_s_j += 1
    elif j == 'B' and y == 'C':
        j_s_b += 1
    elif y == 'B' and j == 'C':
        y_s_b += 1
    elif y == 'C' and j == 'J':
        y_s_c += 1
    elif y == 'J' and j == 'B':
        y_s_j += 1

j_s = j_s_b + j_s_c + j_s_j
j_f = n - j_p - j_s
y_s = y_s_b + y_s_c + y_s_j
y_f = n - y_p - y_s
j_s_most = most_win(j_s_b, j_s_c, j_s_j)
y_s_most = most_win(y_s_b, y_s_c, y_s_j)

print(j_s, j_p, j_f)
print(y_s, y_p, y_f)
print(j_s_most, y_s_most)

编辑于 2017-11-14 14:57:20 回复(0)
#include <iostream>
using namespace std;
int compare(char a,char b)
{
 if((a=='B'&&b=='C')||(a=='C'&&b=='J')||(a=='J'&&b=='B'))
  return 1;//a获胜 
 if((a=='B'&&b=='B')||(a=='C'&&b=='C')||(a=='J'&&b=='J'))
  return 0;//平 
 if((a=='C'&&b=='B')||(a=='J'&&b=='C')||(a=='B'&&b=='J'))
  return -1;//b获胜 
 return 0;
}
int judge(char a)
{
 if(a=='B')
  return 1;
 if(a=='C')
  return 2;
 if(a=='J')
  return 3;
 return 0;
}
char max1(int b,int c,int j)
{
 if(b!=c&&b!=j&&c!=j){
  if(b>c&&b>j)
   return 'B';
  if(c>b&&c>j)
   return 'C';
  if(j>b&&j>c)
   return 'J';
 }else{
  if(b==c&&b>j)
   return 'B';
  if(b==c&&b<j)
   return 'J';
  if(c==j&&c>b)
   return 'C';
  if(c==j&&c<b)
   return 'B';
  if(b==j&&b>c)
   return 'B';
  if(b==j&&b<c)
   return 'C'; 
  if(b==j&&c==j&&b==c)
   return 'B';
 }
 return 'A';
}
int main()
{
 int count1,count2,count3,n,i,c1,j1,b1,b2,c2,j2;
 count1=count2=count3=0;
 c1=j1=b1=b2=c2=j2=0;
 char a,b;
 cin >> n;
 for(i=0;i<n;i++){
  cin >> a >> b;
  if(compare(a,b)==1){
   count1++;
   if(judge(a)==1)
    b1++;
   if(judge(a)==2)
    c1++;
   if(judge(a)==3)
    j1++;
  }
  if(compare(a,b)==0)
   count2++;
  if(compare(a,b)==-1){
   count3++;
   if(judge(b)==1)
    b2++;
   if(judge(b)==2)
    c2++;
   if(judge(b)==3)
    j2++;
  }
 }
 
 //cout << b1 << c1 << j1 <<endl;
// cout << b2 << c2 << j2 <<endl;
 cout << count1 << ' ' << count2 << ' ' << count3 << endl;
 cout << count3 << ' ' << count2 << ' ' << count1 << endl;
 cout << max1(b1,c1,j1) << ' ' << max1(b2,c2,j2) << endl;
 
 return  0;
}

发表于 2017-08-09 12:06:30 回复(0)
#encoding:utf-8

#C:锤子,J:剪刀,B:布
# c>j,j>b,b>c;a1,a2列表作为优势列表;r1,r2作为胜负结果列表(胜,平,负)

a1 = {'J':0,'C':0,'B':0}
a2 = {'J':0,'C':0,'B':0}
r1 = [0,0,0]
r2 = [0,0,0]
tmp = ''
y1=y2=''
times = int(raw_input())
if times:
	for v in range(times):
		t1,t2 = raw_input().split(' ')
		if t1 == 'C' and t2 == 'J':
			r1[0]+=1
			r2[2]+=1
			a1['C']+=1
			# a2['J']+=1
		elif t1 == 'J' and t2 =='C':
			r2[0]+=1
			r1[2]+=1
			a2['C']+=1
			# a1['J']+=1
		elif t1 == 'J' and t2 == 'B':
			r1[0]+=1
			r2[2]+=1
			a1['J']+=1
		elif t1 =='B' and t2 == 'J':
			r2[0]+=1
			r1[2]+=1
			a2['J'] +=1
		elif t1 == 'B' and t2 =='C':
			r1[0]+=1
			r2[2]+=1
			a1['B']+=1
		elif t1 == 'C' and t2 == 'B':
			r2[0]+=1
			r1[2]+=1
			a2['B']+=1
		else:
			r1[1]+=1
			r2[1]+=1
a1 = sorted(a1.iteritems(),key=lambda x:x,reverse=True)
a2 = sorted(a2.iteritems(),key=lambda x:x,reverse=True)
for k,v in a1:
	if v == 0:
		continue
	v = tmp
	y1 = k
	if v>tmp:
		c = tmp
		tmp = v
		v = c
		y1 = k
for k,v in a2:
	if v == 0:
		continue
	v = tmp
	y2 = k
	if v>tmp:
		c = tmp
		tmp = v
		v = c
		y2 = k
if not y1:
	y1 = 'B'
if not y2:
	y2 = 'B'
print '%d %d %d' % tuple(r1)
print '%d %d %d' % tuple(r2)
print '%s %s' % (y1,y2)

			
		
		


发表于 2017-04-11 23:00:37 回复(0)
import java.util.Scanner;

public class Main {
	/*
	 * 数组存储,做差求值,下标输出
	 */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] num = new int[3];// num[0]:甲胜 num[1]:平局 num[2]:乙胜
		char[] b = { 'B', 'C', 'J' };// 哈哈,正好为字母表顺序存储
		int[][] bt = new int[3][2];// bt[i][0]:甲BCJ胜的次数 乙同理
		char[] w = new char[2];
		for (int i = 0; i < n; i++) {
			char t1 = in.next().charAt(0);
			char t2 = in.next().charAt(0);
			int te1 = -10, te2 = -10;
			for (int j = 0; j < b.length; j++) {
				if (t1 == b[j])
					te1 = j;
				if (t2 == b[j])
					te2 = j;
			}
			switch (te1 - te2) {
			case -1:// 甲胜
			case 2:
				num[0]++;  bt[te1][0]++;  break;
				
			case 1:// 乙胜
			case -2:
				
				num[2]++;  bt[te2][1]++;  break;
			default:// 平局
				num[1]++; break;
			}
		}
		System.out.printf("%d %d %d\n", num[0], num[1], num[2]);
		System.out.printf("%d %d %d\n", num[2], num[1], num[0]);
		for (int j = 0; j < 2; j++) {
			int max = bt[0][j];
			int ww = 0;
			for (int i = 1; i < 3; i++) {
				if (bt[i][j] > max) {
					max = bt[i][j];
					ww = i;
				}
			}
			System.out.print(b[ww]);
			if (j != 1)
				System.out.print(" ");
		}
	}
}

发表于 2017-01-15 18:46:02 回复(0)

#include<iostream>
using namespace std;
 
voidfight(charplayerA,charplayerB);
intidexMax(intWinA[3]);
intplayResult[3]={0,0,0},winA[3]={0,0,0},winB[3]={0,0,0};
intmain()
{
    intN;
    charplayerA,playerB;
    charindex[3]={'C','J','B'};
    cin>>N;
    while(N--)
    {
        cin>>playerA>>playerB;
        fight(playerA,playerB);
    }
    cout<<playResult[0]<<" "<<playResult[1]<<" "<<playResult[2]<<endl;
    cout<<playResult[2]<<" "<<playResult[1]<<" "<<playResult[0]<<endl;
    cout<<index[idexMax(winA)]<<" "<<index[idexMax(winB)]<<endl;
    return0;
 
}
//save the player fight result.
voidfight(charplayerA,charplayerB)
{
    if(playerA==playerB)
        playResult[1]++;
    else{
        switch(playerA){
            case'C':
                if(playerB=='B'){//B uses the 'B' win the player
                    playResult[2]++;
                    winB[2]++;
                }else{
                    playResult[0]++;//A uses the 'C' win the player
                    winA[0]++;
                }
            break;
            case'J':
                if(playerB=='C'){//B uses the 'C' win the player
                    playResult[2]++;
                    winB[0]++;
                }else{
                    playResult[0]++;//A uses the 'J' win the player
                    winA[1]++;
                }
            break;
            case'B':
                if(playerB=='J'){//B uses the 'J' win the player
                    playResult[2]++;
                    winB[1]++;
                }else{
                    playResult[0]++;//A uses the 'C' win the player
                    winA[2]++;
                }
            break;
        }
    }
}
 
intidexMax(intwin[3])
{
    inttmp=2;
    if((win[2]>=win[0])&&(win[2]>=win[1])){
        tmp = 2;//output 'B' by priority
        return2;
    }
    elseif((win[0]>=win[1])&&(win[0]>=win[2])){
        tmp = 0;//output 'C'
        return0;
    }
    elseif((win[1]>=win[0])&&(win[1]>=win[2])){
        tmp = 1;//output 'J'
        return1;
    }
    returntmp;
}

发表于 2017-01-15 17:01:10 回复(0)
#include<stdio.h>

int main()
{
	char a,b,Most[3]={'B','C','J'};
	int N,i,compare;
	int RA[3]={0},A[3]={0},B[3]={0};
	

    scanf("%d\n",&N);
	for(i=0;i<N;i++){
		scanf("%c %c",&a,&b);
		getchar(); 
		compare=(int)(a-b);
		if(compare==0)
		RA[1]++;
		if(compare==-7){
			RA[0]++;
			A[1]++;		
		}
		if(compare==7){
			RA[2]++;
			B[1]++;
		}
		if(compare==1){
			RA[2]++;
			B[0]++;
		}
		if(compare==-1){
			RA[0]++;
			A[0]++;
		}
		if(compare==8){
			RA[0]++;
			A[2]++;
		}
		if(compare==-8){
			RA[2]++;
			B[2]++;
		}
	}
		printf("%d %d %d\n",RA[0],RA[1],RA[2]);
		printf("%d %d %d\n",RA[2],RA[1],RA[0]);
		N=0;
		compare=0;
		for(i=1;i<3;i++){
			if(A[i]>A[N])
			N=i;
			if(B[i]>B[compare])
			compare=i;
		}
		printf("%c ",Most[N]);
		printf("%c",Most[compare]);
	
	return 0;
 } 

发表于 2017-01-14 14:04:44 回复(0)

问题信息

难度:
176条回答 24432浏览

热门推荐

通过挑战的用户