[2452일] A. Word (성공)

코드포스 공부기록

목록 보기
19/23


A. Word
time limit per test2 seconds
memory limit per test256 megabytes
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.

cpp

#include<iostream>
#include<string>
#include<cctype>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string s;
	cin >> s;
	int size = s.length(), cnt = 0;
	for (int i = 0; i < size; i++)
	{
		if (isupper(s[i])) cnt++;
	}
	if (size - cnt < cnt)
	{
		for (int i = 0; i < size; i++)
		{
			cout << (char) toupper(s[i]);
		}
	}
	else
	{
		for (int i = 0; i < size; i++)
		{
			cout <<(char) tolower(s[i]);
		}
	}
	return 0;
}

c#

using System;
using System.IO;
using System.Text;
using System.Threading;
using System.Linq;
class Program
{
    static BufferedStream sb = new BufferedStream(Console.OpenStandardInput());
    static StreamReader sr = new StreamReader(new BufferedStream(Console.OpenStandardInput()), Encoding.Default);
    static StreamWriter sw = new StreamWriter(new BufferedStream(Console.OpenStandardOutput()), Encoding.Default);
    static int ReadInt()
    {
        int c = sb.ReadByte();
        while (c <= 32) { if (c == -1) return -1; c = sb.ReadByte(); }
        bool neg = false;
        if (c == '-') { neg = true; c = sb.ReadByte(); }
        int val = 0;
        while (c > 32)
        {
            val = val * 10 + (c - '0');
            c = sb.ReadByte();
        }
        return neg ? -val : val;
    }
    static void Solve()
    {
        string s = sr.ReadLine();
        if (s.Count(char.IsUpper) > s.Count(char.IsLower))
        {
            sw.Write(s.ToUpper());
        }
        else sw.Write(s.ToLower());
            sw.Flush();
    }
    static void Main(string[] args)
    {
        Thread thread = new Thread(Solve, 1024 * 1024 * 32);
        thread.Start();
        thread.Join();
    }
}

python3

import sys
input = sys.stdin.readline
# data = sys.stdin.buffer.read()
# ndata = len(data)
# ii = 0
# def read_int():
#     global ii, ndata, data
#     while ii < ndata and data[ii] <= 32:
#         ii += 1
#     if ii >= ndata:
#         return 0
#     sign = 1
#     if data[ii] == 45:  # ASCII 45 == '-'
#         sign = -1
#         ii += 1
#     num = 0
#     while ii < ndata and data[ii] > 32:
#         num = num * 10 + (data[ii] - 48)
#         ii += 1
#     return num * sign
s=input().rstrip()
upper=sum( 1  for x in s if x.isupper())
lower=sum( 1  for x in s if x.islower())
if upper>lower:
    print(s.upper())
else:
    print(s.lower())

대충 문제가 알파벳 대문자 소문자 섞어쓰는게 짜증나서
하나로 통일하겠다는 건데
출력에서 보면 대문자가 많으면 대문자 반대면 소문자로 통일해서 춢력하는 문제로 해석됨. ㄱ

0개의 댓글