atcoder ABC 357-B题详解

atcoder ABC 357-B题详解

Problem Statement

You are given a string S consisting of lowercase and uppercase English letters. The length of S is odd.
If the number of uppercase letters in S is greater than the number of lowercase letters, convert all lowercase letters in S to uppercase.
Otherwise, convert all uppercase letters in S to lowercase.

Constraints

S is a string consisting of lowercase and uppercase English letters.
The length of S is an odd number between 1and 99, inclusive.

Input

The input is given from Standard Input in the following format:

S

Output

Print the string S after converting the letters according to the problem statement.

Sample Input 1

AtCoder

Sample Output 1

atcoder
The string AtCoder contains five lowercase letters and two uppercase letters. Thus, convert all uppercase letters in AtCoder to lowercase, which results in atcoder.

Sample Input 2

SunTORY

Sample Output 2

SUNTORY
The string SunTORY contains two lowercase letters and five uppercase letters. Thus, convert all lowercase letters in SunTORY to uppercase, which results in SUNTORY.

Sample Input 3

a

Sample Output 3

a

思路分析:

定义一个字符串,用ans存小写字母的个数,用cnt存大写字母的个数,根据题意拿个需要转化,就转化拿个。

code:

#include <iostream>
#include <string>
using namespace std;
string v;
int ans;
int cnt;
int main(){
        cin>>v;
    for(int i=0;i<v.size();i++){
        if(v[i]>='a'){
            ans++;
        }
        if(v[i]>='A'&&v[i]<'a'){
            cnt++;
        }
    }
    if(ans>=cnt){
        for(int i=0;i<v.size();i++){
            if(v[i]>='A'&&v[i]<'a'){
                v[i]=v[i]+('a'-'A');
            }
        }
    }
    else {
        for(int i=0;i<v.size();i++){
            if(v[i]>='a'){
                v[i]=v[i]-('a'-'A');
            }
        }
    }
    for(int i=0;i<v.size();i++){
        cout<<v[i];
    }
}
  • 7
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值