Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1982827148 opened this issue Aug 4, 2022 · 0 comments
Open

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

1982827148 opened this issue Aug 4, 2022 · 0 comments

Comments

@1982827148
Copy link

1982827148 commented Aug 4, 2022

#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;
}
@1982827148 1982827148 changed the title PAT-B 1018. 锤子剪刀布 (20)(最简洁的写法) PAT-B 1018. 锤子剪刀布 (20)(最简洁巧妙的写法) Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant