Codeforces Round #242 (Div. 2) A. Squats

简单模拟题。

思路:统计小写字母的个数low_letter。

   a.如果等于n/2直接输出0,输出原字符串 。

   b.如果大于n/2,将low_letter - n/2的小写字母变成大写字母即可,输出low_letter,输出变化后的字符串。

   c.如果小于n/2,将low_letter - n/2的大写字母变成小写字母即可,输出low_letter,输出变化后的字符串。

#include <stdio.h>
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <map>

using namespace std;
const int maxn = 205;
char str[maxn];
int main(){
    int n;
    while(~scanf("%d",&n)){
        scanf("%s",str);
        int len = (int)strlen(str);
        int low_letter = 0;
        for(int i = 0;i < len;i++){
            if(str[i] == 'x')
                low_letter++;
        }
        if(low_letter == n/2){
            printf("0\n");
            puts(str);
            continue;
        }
        int flag = 0;
        if(low_letter > n/2){
            low_letter = n - low_letter;
            flag = 1;
        }
        int ans = 0;
        if(!flag)
            for(int i = 0;i < len;i++){
                if(str[i] == 'X'){
                    str[i] = 'x';
                    ans++;
                }
                if(ans >= n/2 - low_letter)
                    break;
            }
        else
            for(int i = 0;i < len;i++){
                if(str[i] == 'x'){
                    str[i] = 'X';
                    ans++;
                }
                if(ans >= n/2 - low_letter)
                    break;
            }
        printf("%d\n",ans);
        puts(str);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值