每日一题:团队程序设计天梯赛模拟赛--L1-044 稳赢改编版

团队程序设计天梯赛模拟赛里面的题,是对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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值