Skip to content

PAT-B 1018. 锤子剪刀布 (20)(最简洁巧妙的写法) #168

Description

@1982827148
#include<iostream>
using namespace std;
typedef long long ll;
int n,w1,w2;
int win1[3],win2[3];
int change(char c) {
	if(c=='B') return 0;
	else if(c=='C') return 1;
	else return 2;
}
int main() {
	cin>>n;
	for(int i=0; i<n; i++) {
		char a,b;
		cin>>a>>b;
		int k1=change(a),k2=change(b);//由于后续将按字典序排序输出胜利次数最多的手势,可将B、C、J分别编码下标对应 0 1 2,
		if((k1+1)%3==k2) { //又由于B、C、j循环相克,经分析可巧妙地发现得k1赢k2的条件是 (k1+1)%3==k2,
			w1++;
			win1[k1]++;
		} else if((k2+1)%3==k1) {
			w2++;
			win2[k2]++;
		}
	}
	cout<<w1<<" "<<n-w1-w2<<" "<<w2<<endl;
	cout<<w2<<" "<<n-w1-w2<<" "<<w1<<endl;
	char m[3]= {'B','C','J'};
	int a=0,b=0;
	for(int i=1; i<3; i++) {
		if(win1[i]>win1[a])a=i;
		if(win2[i]>win2[b]) b=i;
	}
	cout<<m[a]<<" "<<m[b];
	return 0;
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions