关于一些初级ACM竞赛题目的分析和题解(十)

关于一些初级ACM竞赛题目的分析和题解(十) 

   西面的题目是关于一些字母变换的,上题:

A. Word
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Examples
input
HoUse
output
house
input
ViP
output
VIP
input
maTRIx
output
matrix

输入
第一行包含一个单词s - 由大写和小写拉丁字母组成,长度从1到100。
输出
打印纠正的单词s。 如果给定的单词s具有更多的大写字母,则将该单词写入大写寄存器中,否则  以小写字母写入。

题意即一行字符串若是大写字母数大于小写字母数则把这一行字符变为大写,反之,变为小写,下面是代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int l,c,b;
int main()
{
    char a[300];

    scanf("%s",a);
    l=strlen(a);
    for (int i=0;i<l;i++)
        {
        if(a[i]>=97)c++;  //不同类型计数
        else b++;
        }
    if (c>=b)  // 比较大小写的字符数目
    {
        for (int j=0;j<l;j++)
            if(a[j]<97)a[j]+=32;  //执行
        return 0*printf("%s",a);
    }
        if (c<b)
    {
        for (int j=0;j<l;j++)
            if(a[j]>=97)a[j]-=32;
        return 0*printf("%s",a);  //  输出结果
    }


}








發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章