forked from prateekshyap/DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Word.java
33 lines (31 loc) · 845 Bytes
/
Word.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*https://codeforces.com/problemset/problem/59/A*/
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
public class Word
{
public static void main(String[] args)throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
char[] str = br.readLine().toCharArray();
StringBuilder result = new StringBuilder("");
int[] hash = new int[26];
for (char ch : str)
{
if (ch >= 'a' && ch <= 'z')
++hash[ch-'a'];
else
--hash[ch-'A'];
}
int sign = 0;
for (int i = 0; i < 26; ++i)
sign += hash[i];
if (sign >= 0)
for (char ch : str)
result.append((ch >= 'a' && ch <= 'z') ? ch : (char)((int)ch+32));
else
for (char ch : str)
result.append((ch >= 'a' && ch <= 'z') ? (char)((int)ch-32) : ch);
System.out.println(result);
}
}