思路:
1.可将B,C,J 布,锤子,剪刀的大小关系分别进行出现判断,借此对甲和乙的输赢或平局进行判断
2.输赢和平局的记录分别进行,判断后即给出
3.按题目要求输出结果
注意:
1.各类情况要覆盖到,且注意甲和乙种某一人没有赢过时,结果仍需输出,默认为最小字母序的B
2.输出赢次数最多的最小字母序字母,可直接按B、C、J的次序进行输出(无论有无次数相同)
3.查找最值的代码模式需注意是与num[MAX]比较,而非MAX(此仅为index,不是具体值)
# include
using namespace std;
int main()
{
int R1[5]={0,0,0,0,0},R2[5]={0,0,0,0,0},num=0; //order B,C,J 布,锤子,剪刀 victory:0-2,平:3,负:4
char A,B;
int V1=0,V2=0;
cin>>num;
for(int i=0;i<num;i++)
{
cin>>A>>B;
if((A=='B'&&B=='B')||(A=='C'&&B=='C')||(A=='J'&&B=='J'))
{
R1[3]++;
R2[3]++;
}
else if(A=='B'&&B=='C')
{
R1[0]++;
R2[4]++;
}
else if(A=='C'&&B=='J')
{
R1[1]++;
R2[4]++;
}
else if(A=='J'&&B=='B')
{
R1[2]++;
R2[4]++;
}
else if(A=='C'&&B=='B')
{
R1[4]++;
R2[0]++;
}
else if(A=='J'&&B=='C')
{
R1[4]++;
R2[1]++;
}
else if(A=='B'&&B=='J')
{
R1[4]++;
R2[2]++;
}
}
cout<<R1[0]+R1[1]+R1[2]<<' '<<R1[3]<<' '<<R1[4]<<endl;
cout<<R2[0]+R2[1]+R2[2]<<' '<<R2[3]<<' '<<R2[4]<<endl;
for(int j=0;j<3;j++)
{
if(R1[j]>R1[V1])
{
V1=j;
}
if(R2[j]>R2[V2])
{
V2=j;
}
}
if(V1==0)
{
cout<<'B';
}
else if(V1==1)
{
cout<<'C';
}
else
{
cout<<'J';
}
if(V2==0)
{
cout<<' '<<'B'<<endl;
}
else if(V2==1)
{
cout<<' '<<'C'<<endl;
}
else
{
cout<<' '<<'J'<<endl;
}
return 0;
}
结果:
PLUS其他解法(搬运):
1.https://blog.csdn.net/t4ngw/article/details/122830342
2.https://www.jianshu.com/p/a767434d9ded
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)