ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 4-C, *1300
    코드포스 2021. 7. 25. 15:09
     

    Problem - 4C - Codeforces

     

    codeforces.com

    문제

    • $n(1\leq n \leq 10^{5})$번 32자 이하의 알파벳 소문자로 이루어진 이름이 주어진다
    • 처음보는 이름은 "OK", $k$번 본 이름은 "준_이름$k$" 를 출력한다
    • $O(nlog\ n)$ 정도의 알고리즘은 통과 가능하다

     

    $O(nlog\ n)$

    map을 이용하여 이름을 저장한다

    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
    #include <bits/stdc++.h>
    #define endl "\n"
    using namespace std;
     
    map<stringint> m;
     
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0), cout.tie(0);
     
        int n;
        cin >> n;
        string name;
        while(n--){
            cin >> name;
            if(m.find(name) != m.end()){
                m[name]++;
                cout << name << m[name] << endl;
            }
            else{
                cout << "OK" << endl;
                m[name] = 0;
            }
        }
     
        return 0;

    '코드포스' 카테고리의 다른 글

    189-A, *1300  (0) 2021.07.27
    230-B, *1300  (0) 2021.07.27
    1360-C, *1100  (0) 2021.07.25
    82-A, *1100  (0) 2021.07.25
    1366-B, *1300  (0) 2021.07.24

    댓글

Designed by Tistory.