2020.10.03天梯赛练习1题解-qfnu

7-1谁先倒

题意:本人语文功底太差,有些许不是很明白,但是这个是这个水题,也没必要深究
#include <iostream>
using namespace std;

int A,B;
int n;
int a,b,c,d;
int j,y;

int main()
{
    cin >> A >> B;
    cin >> n;
    int ying = 0;
    while(n --)
    {
        cin >> a >> b >> c >> d;
        
        int e = a + c;
        
        if(ying != 0){
            continue;
        }
        
        if(e == b && e == d){
            j++;
            y++;
        }
        else if(e == b){
            j++;
        }
        else if(e == d){
            y++;
        }
        
        if(j >= A){
            ying = 2;
        }
        
        if(j >= B){
            ying = 1;
        }
        
        
    }
    
    if(ying == 1){
        cout << 'A' << endl;
        cout << y << endl;
    }
    else{
        cout << 'B' << endl;
        cout << j << endl;
    }
    
    
    return 0;
}
结果只是得了14分,主要是题意还是没读明白

7-2 重要的话说三遍

题意:把一串字符串输出三遍就好了
#include <iostream>
using namespace std;

int A,B;
int n;
int a,b,c,d;
int j,y;

int main()
{
    printf("I'm gonna WIN!\n");
    
    printf("I'm gonna WIN!\n");
    printf("I'm gonna WIN!\n");
    
    return 0;
}

7-3 奇偶分家

题意:给定N个正整数,请统计奇数和偶数各有多少个?
#include <iostream>
using namespace std;

int main()
{
    int n;
    int odd = 0;
    
    cin >> n;
    for(int i = 0;i < n;i ++)
    {
        int x;
        cin >> x;
        if(x & 1){
            odd++;
        }
    }
    
    cout << odd << ' ' << n - odd << endl;
    
    return 0;
}

7- 4 输出GPLT

题意:给定一个长度不超过10000的、仅由英文字母构成的字符串。请将字符重新调整顺序,按GPLTGPLT…这样的顺序输出,并忽略其它字符。当然,四种字符(不区分大小写)的个数不一定是一样多的,若某种字符已经输出完,则余下的字符仍按GPLT的顺序打印,直到所有字符都被输出。
/*
统计出gplt每个字符的个数,然后按照顺序有啥输出啥就OK了
*/

#include <iostream>
using namespace std;

int a,b,c,d;
int main()
{
    string str;
    cin >> str;
    for(int i = 0;str[i];i ++)
    {
        if(str[i] == 'G' || str[i] == 'g'){
            a++;
        }
        else if(str[i] == 'P' || str[i] == 'p'){
            b++;
        }
        else if(str[i] == 'L' || str[i] == 'l'){
            c++;
        }
        else if(str[i] == 'T' || str[i] == 't'){
            d++;
        }
    }
    
    while(1)
    {
        if(a){
            a--;
            cout << 'G';
        }
        if(b){
            b--;
            cout << 'P';
        }
        if(c){
            c--;
            cout << 'L';
        }
        if(d){
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值