만족은 하되 안주하지는 말자

기록해야 기억한다

프로그래밍/programmers&bj

[C++][알고리즘] 백준 1157번 단어 공부

D36choi 2020. 3. 12. 15:57
728x90

https://www.acmicpc.net/problem/1157

[

1157번: 단어 공부

알파벳 대소문자로 된 단어가 주어지면, 이 단어에서 가장 많이 사용된 알파벳이 무엇인지 알아내는 프로그램을 작성하시오. 단, 대문자와 소문자를 구분하지 않는다.

www.acmicpc.net

](https://www.acmicpc.net/problem/1157)

https://en.cppreference.com/w/cpp/language/ascii

[

ASCII Chart - cppreference.com

The following chart contains all 128 ASCII decimal (dec), octal (oct), hexadecimal (hex) and character (ch) codes. dec oct hex ch dec oct hex ch dec oct hex ch dec oct hex ch 0 0 00 NUL (null) 32 40 20 (space) 64 100 40 @ 96 140 60 ` 1 1 01 SOH (start of h

en.cppreference.com

](https://en.cppreference.com/w/cpp/language/ascii)

ASCII 코드의 Decimal number 를 이용하여 풀었다.

대문자와 소문자의 갯수를 alphabet[26] 에 기록한 뒤 가장 큰 index를 찾고, 가장 많은 갯수의

알파벳이 여러개일 경우가 있나를 확인 후 해당 경우가 없다면 answer alphabet(대문자!) 를 출력한다.

기본적으로 'a' 는 decimal number = 97 에 대응하고

대문자 'A' 는 65에 대응한다.

a-97 = 0

A-65 = 0

alphabet[0] 은 'a' or 'A' 의 갯수를 기록한다고 보면 된다.

코드