#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int main(){
int n1,n2;
char word[110];
while(scanf("%s",&word)!=EOF){
n1 = n2 = 0;
int i = 0;
while(word[i] != '\0'){
if(word[i] < 97){
n2++;
}
else{
n1++;
}
i++;
}
// cout<<n1<<endl<<n2;
if(n1 >= n2){
i = 0;
while(word[i] != '\0'){
if(word[i] < 97){
word[i]+=32;
}
i++;
}
}
else{
i = 0;
while(word[i] != '\0'){
if(word[i] >= 97){
word[i]-=32;
}
i++;
}
}
cout<<word<<endl;
}
} 直接记录小写和大写字母数量,再根据哪边数量多对原字符串进行变换
本文介绍了一个简单的C++程序,该程序能够读取一个字符串并统计其中的大写和小写字母数量。根据数量的多少,程序将字符串转换为全大写或全小写形式。
1175

被折叠的 条评论
为什么被折叠?



