- 白夜的强迫症
白夜有强迫症,他看到一串大小写混杂的字符串就会不开心。如果他看到这样的字符串,他会选择把它修改成全部大写或者全部小写。但他又不想在这上面花费太多的时间,所以他想修改最少的次数达到他的目的。给定一个字符串,你能推断出他修改后的字符串是什么样子的吗?
P.S.:如果改成全部大写和改成全部小写的修改次数一样,这两种情况都有可能,你可以选择任意输出一个或者全部输出
输入:一个仅含英文字母的字符串 输出:修改后的字符串
例如输入:HelloWorld 输出:helloworld
#include<stdio.h>
#include<ctype.h>
int main()
{
char a[100],ch;
int i=0,b=0,s=0,net=0;
do
{
scanf("%1c",&a[i]);
if(a[i]>='a'&&a[i]<='z')
{
s++;
}
if(a[i]>='A'&&a[i]<='Z')
{
b++;
}
i++;
}while(getchar()!='\n');
if(b>=s)
{
for(net=0;net<i;net++)
{
ch= toupper(a[net]);
printf("%c",ch);
}
}
if(b<s)
{
for(net=0;net<i;net++)
{
ch= tolower(a[net]);
printf("%c",ch);
}
}
}