团队程序设计天梯赛模拟赛里面的题,是对L1-044 稳赢进行了一个大改编,难度加大了不少,从15分的难度加到20分的难度
题意是对方出石头剪刀布
如图所示输入,直到End结束
我们已经预先知道了对方要出的所有,我们可以轻松地赢对方,但是为了不让对方看出我们能控制局面,给出n个数字,比如3个数字:2,3,4,要求我们赢2局输1局,赢3局输1局,赢4局输1局,如果对方出招非常多的话,那么就这样轮回,赢2局输1局...
输出我方出的招(石头剪刀布)
string s是可以直接比较大小的,包括>,<.==.!=
当然,也可以直接用等号赋值(相比之下,char s[100]需要用字符串函数strcpy)
string s 可以+=字符或者字符串
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
string s;
s="happy";
s+='h';
s+="aha";
cout<<s<<endl;
return 0;
}
char s[100]不能用==来判断是否和某个字符串相等
应该用字符串函数strcmp,strcmp(s1,s2)==0表示相等
如下图:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string.h>
using namespace std;
char s[100];
int main()
{
strcpy(s,"happy");
// if(s=="happy")
printf("%s\n",s);
return 0;
}
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string.h>
using namespace std;
char s[100];
int main()
{
strcpy(s,"happy");
if(s=="happy")
printf("%s\n",s);
return 0;
}
可以用一个结构体数组把对方所有的出招全都记录下来,包括对方出招的总数量cnt
对方每出一招,我方应一招,只需判断什么时候输什么时候赢就行了
sum2是对2,3,4进行轮回的(给出n个数字,比如3个数字:2,3,4)
x用来枚举是第几个数字(1,2,3)的,a[1]=2,a[2]=3,a[3]=4
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string.h>
#include<cstdio>
using namespace std;
const int N=100010;
int a[N];
struct Node{
string s;
}q[N];
int cnt;
int sum2;
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++) {
cin>>a[i];
}
string s1;
cin>>s1;
q[cnt].s=s1;
while(s1!="End"){
cin>>s1;
q[++cnt].s=s1;
}
int x=1;
for(int i=0;i<cnt;i++){
sum2++;
if(sum2<=a[x]){
if(q[i].s=="ChuiZi") printf("Bu\n");
if(q[i].s=="JianDao") printf("ChuiZi\n");
if(q[i].s=="Bu") printf("JianDao\n");
}
if(sum2==a[x]){
i++;
if(q[i].s=="ChuiZi") printf("JianDao\n");
if(q[i].s=="JianDao") printf("Bu\n");
if(q[i].s=="Bu") printf("ChuiZi\n");
sum2=0;
x++;
if(x==n+1) x=1;
}
}
return 0;
}