c++/알고리즘

백준 1159

hojung 2022. 3. 18.
728x90
반응형

//백준 1159번
#include <iostream>
#include <string>
using namespace std;
int cnt[26];
int n;
string player;
string ret;
int main() {

    cout << "enter your player number" << endl;
    cin >> n;
    for(int i= 0; i < n ; i ++ )
    {
        cout << "enter your player name" << endl;
        cin >> player;
        cnt[player[0] - 'a']++;
    }
    
    for(int i = 0; i < 26; i ++ )
    {
        if(cnt[i] >= 5)
        {
            ret += i+ 'a';
        }
    }
    if(ret.size()) cout << ret << " ";
    else cout << "PREDAJA" << endl;
    return 0;
}

새로 안 사실 

  • string 문자열을 표현할 때 아스키코드로써 표현할 수 있는데 이는 int형과 char형 자료형을 더해서도 만들 수 있다. 
  • player는 따로 입력받는 공간이 필요하지 않다 판단을 하는 데에만 쓰인다. 
728x90
반응형

'c++ > 알고리즘' 카테고리의 다른 글

백준2178번-미로BFS  (0) 2022.03.28
shell sort c++  (0) 2022.03.23
백준 9996  (0) 2022.03.19
c++ 행렬 곱셈  (0) 2022.03.16
피보나치 수열  (0) 2022.03.16

댓글