關於一些初級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);  //  輸出結果
    }


}








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