石头剪刀布是常见的猜拳游戏。石头胜剪刀,剪刀胜布,布胜石头。如果两个人出拳一样,则不分胜负。 一天,小A和小B正好在玩石头剪刀布。已知他们的出拳都是有周期性规律的,比如:“石头-布-石头-剪刀-石头-布-石头-剪刀……”,就是以“石头-布-石头-剪刀”为周期不断循环的。请问,小A和小B比了N轮之后,谁赢的轮数多?
然后是输入输出描述in 输入包含三行。 第一行包含三个整数:N,NA,NB,分别表示比了N轮,小A出拳的周期长度,小B出拳的周期长度。0 < N,NA,NB < 100。 第二行包含NA个整数,表示小A出拳的规律。 第三行包含NB个整数,表示小B出拳的规律。 其中,0表示“石头”,2表示“剪刀”,5表示“布”。相邻两个整数之间用单个空格隔开。 out 小A赢输出A,小B赢输出B,平局输出draw 我把代码发一下
#include<bits/stdc++.h>
using namespace std;
int n,na[104],ma,nb[104],mb;
int ansa=0,ansb=0,ansd=0;
int a,b;
void tp(int a,int b){
if(a==0&&b==2){
ansa++;
}
else if(a==0&&b==5){
ansb++;
}
else if(a==0&&b==0){
ansd++;
}
else if(a==2&&b==0){
ansb++;
}
else if(a==2&&b==5){
ansa++;
}
else if(a==2&&b==2){
ansd++;
}
else if(a==5&&b==0){
ansa++;
}
else if(a==5&&b==2){
ansb++;
}
else if(a==5&&b==5){
ansd++;
}
}
int main(){
cin>>n>>ma>>mb;
for(int i=0;i<ma;i++){
cin>>na[i];
}
for(int j=0;j<mb;j++){
cin>>nb[j];
}
for(int i=0,j=0;i<ma,j<mb;i++,j++){
if(i==ma){
a=na[0];
}
if(j==mb){
b=nb[0];
}
a=na[i];
b=nb[j];
tp(a,b);
}
if(ansa>ansb)
printf("A\n");
else if(ansa<ansb)
printf("B\n");
else
printf("draw\n");
return 0;
}
交这个代码得了8分 是在NOI上的题 想去的看传送门 NOI 1.6 第8题 剪刀石头布 麻烦大家看完给我答复谢谢!