1157번: 단어 공부
Difficulty: Bronze I
Problem Description
You will get a string. You have to find out which alphabet is used the most frequently.
You should not bo case sensitive.
The output is the most frequently used alphabet if it exists only one. Otherwise, print '?'.
Solution
Arr is for storing the number of alphabets alphabetically.
Str is for input string. It will be changed to all uppercase letters.
If the conditional value is 0, it means the letter didn't counted before.
So count the letter and store it in arr.
Idx is the index of the max value of arr. If the max value exists after the index,
it means there are more than 2 alphabets which are the most frequently used. So print '?'.
Otherwise, print the most frequently used alphabet.
Today's English
case sensitive : 대소문자 구분
alphabetically : 알파벳 순서대로
uppercase : 대문자
Today's Code
str.upper() : str를 전무 대문자로 변환
ord(x) : 문자 x의 아스키코드 번호를 반환
chr(x) : ord의 반대되는 기능으로, 아스키코드 x에 해당하는 문자를 반환
str.count(a) : 문자열 str에서 a가 등장하는 횟수를 반환
여담
난이도는 브론즈 1로 책정되어 있는데 푸는 시간은 거의 실버 상위 등급 정도가 걸렸다.
런타임 에러가 발생하는 것을 보고 문자열의 길이가 너무 길어서 발생하는 문제로 착각해 문자열을 dynamic하게 count하거나 일부분을 끊어서 count하는 방법 등을 시도해 봤다.
결론은 알고리즘의 문제였고, 알고리즘의 문제를 고치니 문제가 해결되었다.