YTUOJ-The mixed letters

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++;于是什么都没有输出。

时间: 2024-11-09 03:58:27

YTUOJ-The mixed letters的相关文章

[USACO08NOV]奶牛混合起来Mixed Up Cows

题目描述 Each of Farmer John's N (4 <= N <= 16) cows has a unique serial number S_i (1 <= S_i <= 25,000). The cows are so proud of it that each one now wears her number in a gangsta manner engraved in large letters on a gold plate hung around her

洛谷 P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows

P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows 题目描述 Each of Farmer John's N (4 <= N <= 16) cows has a unique serial number S_i (1 <= S_i <= 25,000). The cows are so proud of it that each one now wears her number in a gangsta manner engraved in large le

Bzoj 2789: [Poi2012]Letters 树状数组,逆序对

2789: [Poi2012]Letters Time Limit: 20 Sec  Memory Limit: 128 MBSubmit: 278  Solved: 185[Submit][Status][Discuss] Description 给出两个长度相同且由大写英文字母组成的字符串A.B,保证A和B中每种字母出现的次数相同. 现在每次可以交换A中相邻两个字符,求最少需要交换多少次可以使得A变成B. Input 第一行一个正整数n (2<=n<=1,000,000),表示字符串的长度

[LeetCode][JavaScript]Remove Duplicate Letters

Remove Duplicate Letters Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest in lexicographical order among all possible results

如何透过HTC Vive拍摄Mixed Reality (混合现实)影片

https://www.vive.com/cn/forum/1706?extra=page%3D1 也许你是一位开发者,想为自己的HTC Vive游戏制作酷炫的宣传片:或者你是游戏主播,想为观众带来高质量的VR直播体验:甚至你是一位VR的爱好者.无论如何,如果你对Mixed Reality(混合现实)感兴趣,请继续看下去.本文将介绍如何用HTC Vive拍摄高质量MR视频. ======================================================== 什么是M

316. Remove Duplicate Letters

316. Remove Duplicate Letters Total Accepted: 2367 Total Submissions: 12388 Difficulty: Medium Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your resu

[leetcode] Remove Duplicate Letters

题目: Given a string which contains only lowercase letters, remove duplicate letters so that every letter appear once and only once. You must make sure your result is the smallest in lexicographical order among all possible results. Example: Given "bca

用GPIO_WriteBit时产生enumerated type mixed with another type警告

在keil里面写STM32程序,这样写GPIO_WriteBit(GPIOC,GPIO_Pin_9,1),编译的时候就报enumerated type mixed with another type警告,  这说明数据类型混用了,进入GPIO_WriteBit函数发现其原型是void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal)这样的 ,BitAction这个是枚举,所以要类型转换 即把GPIO_W

git reset soft,hard,mixed之区别深解

GIT reset命令,似乎让人很迷惑,以至于误解,误用.但是事实上不应该如此难以理解,只要你理解到这个命令究竟在干什么. 首先我们来看几个术语 HEAD 这是当前分支版本顶端的别名,也就是在当前分支你最近的一个提交 Index index也被称为staging area,是指一整套即将被下一个提交的文件集合.他也是将成为HEAD的父亲的那个commit Working Copy working copy代表你正在工作的那个文件集 Flow 当你第一次checkout一个分支,HEAD就指向当前