首页 > 其他 > 详细

YTUOJ-The mixed letters

时间:2015-04-03 09:31:47      阅读:437      评论:0      收藏:0      [点我收藏+]

Description

Mike is very upset that many people on the Internet usually mix uppercase and lowercase letters in one word. That‘s why he decided to invent an extension for his favorite browser that would change the letters‘ case in every word so that it either only consisted of lowercase letters or only consisted of uppercase ones. And he wants to change as few letters as possible in the word.
For example, the word "HoUse" must be changed to "house", and the word "ViP", to "VIP".
If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, "maTRIx" should be changed to "matrix".
You task is to use the given method to change the given word.

Input

The first line contains a single integer n (n<=30), indicating the number of test cases.
Then following n lines, each line contains a word s, it consists of uppercase and lowercase
Latin letters and its length is between 1 and 100, inclusive.

Output

Print the word s after change. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise, in the lowercase one.

Sample Input

3
HoUse
ViP
maTRIx

Sample Output

house
VIP
matrix

HINT

代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
    int T;
    char c[31];
    cin>>T;
    while (T--)
    {
        cin>>c;
        int len=strlen(c);
        int i=0,m=0,n=0;
        while (c[i]!='\0')
        {
            if (c[i]>='a'&&c[i]<='z')
                m++;
            else if (c[i]>='A'&&c[i]<='Z')
                n++;
            i++;
        }
        i=0;
        if (m>=n)
        {
            while (c[i]!='\0')
            {
                if (c[i]>='A'&&c[i]<='Z')
                {
                    c[i]+=32;
                }
                i++;
            }
        }
        else
        {
            while (c[i]!='\0')
            {
                if (c[i]>='a'&&c[i]<='z')
                {
                    c[i]-=32;
                }
                i++;
            }
        }
        for (i=0;i<len;i++)
        {
            cout<<c[i];
        }
        cout<<endl;
    }
    return 0;
}


运行结果:

技术分享

 

这道题的意思倒是一下子就看懂了。一个字符串中如果小写字母的数目大于或等于大写字母的数目,则将所有字母转化为小写后输出,反之则转化为大写。

为了字符串的输入输出又忙活半天,唉唉,发现用到while(c[i]!=‘\0‘)的时候总是忘记i++;于是什么都没有输出。

YTUOJ-The mixed letters

原文:http://blog.csdn.net/liuchang54/article/details/44836165

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!