๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป/๋ฐฑ์ค€(BOJ)

[๋ฐฑ์ค€,c++] 1371๋ฒˆ - ๊ฐ€์žฅ ๋งŽ์€ ๊ธ€์ž

by dkswnkk 2021. 11. 5.
 

1371๋ฒˆ: ๊ฐ€์žฅ ๋งŽ์€ ๊ธ€์ž

์ฒซ์งธ ์ค„๋ถ€ํ„ฐ ๊ธ€์˜ ๋ฌธ์žฅ์ด ์ฃผ์–ด์ง„๋‹ค. ๊ธ€์€ ์ตœ๋Œ€ 50๊ฐœ์˜ ์ค„๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๊ณ , ๊ฐ ์ค„์€ ์ตœ๋Œ€ 50๊ฐœ์˜ ๊ธ€์ž๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. ๊ฐ ์ค„์—๋Š” ๊ณต๋ฐฑ๊ณผ ์•ŒํŒŒ๋ฒณ ์†Œ๋ฌธ์ž๋งŒ ์žˆ๋‹ค. ๋ฌธ์žฅ์— ์•ŒํŒŒ๋ฒณ์€ ์ ์–ด๋„ ํ•˜๋‚˜ ์ด

www.acmicpc.net

#include <iostream>
#include <string>
using namespace std;
char alphabet[26] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
int check[26];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;

    while (cin >> s) {
        for (int i = 0; i < s.length(); i++) {    //์•ŒํŒŒ๋ฒณ ๊ฐฏ์ˆ˜ ํƒ์ƒ‰
            for (int k = 0; k < 26; k++) {
                if (s[i] == alphabet[k]) check[k]++;
            }
        }
    }
    int maxIndex = 0;
    for (int i = 0; i < 26; i++) {    //์•ŒํŒŒ๋ฒณ ๊ฐฏ์ˆ˜๊ฐ€ ์ ค ๋งŽ์€๊ฒŒ ๋ช‡๊ฐœ์ธ์ง€ ํƒ์ƒ‰
        if (check[i] > maxIndex) {
            maxIndex = check[i];
        }
    }
    for (int i = 0; i < 26; i++) {
        if (check[i] == maxIndex) cout << alphabet[i];    //์ตœ๋Œ€ ๊ฐฏ์ˆ˜๊ฐ€ ์ค‘๋ณต์ผ์ˆ˜๊ฐ€ ์žˆ์œผ๋‹ˆ ์ „๋ถ€์ถœ๋ ฅ
    }
}

๋Œ“๊ธ€