Codeforces习题 59A Word

发布于 / 技术 / 0 条评论

Question

Vasya is very upset that many people on the Net 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’ register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with 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 replaced by matrix. Your task is to use the given method on one given word.

Input

The first line contains a word s — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.

Output

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

这道题的题目是依据一个字符串中大写或者小写字母的个数来将一个大小写混合的字符串转换到纯大写或纯小写的状态并输出。所以程序分为两个部分:

  1. 将整个字符串的大写字符和小写字符统计出来并比较大小。
  2. 根据上一步的结果将字符串转换后的结果输出出来。

实际上也有别的更快的方法来解决,例如,判断每个字符大小写后只计算大写字符数量,字符串减去大写字符就是小写字符的数量。通过前文所述的方法我们可以得到代码。

INPUT_WORD = str(input())
LatinLow = 'abcdefghijklmnopqrstuvwxyz'
LatinUp = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
LOWERCASE_NUM = 0
UPPERCASE_NUM = 0
for i in INPUT_WORD:
    if i in LatinLow:
        LOWERCASE_NUM += 1
    else:
        UPPERCASE_NUM += 1
if LOWERCASE_NUM >= UPPERCASE_NUM:
    print(INPUT_WORD.lower())
else:
    print(INPUT_WORD.upper())

该代码即可提交并通过测试。

本网站在未特殊说明的情况下采用知识共享署名-非商业性使用-相同方式共享 3.0 协议进行许可。
<-数据丢失->