Baekjoon(C++)

[C++]백준 알고리즘 10809번

DanielSoliph 2021. 7. 14. 22:23

풀이는 아래와 같다.

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
#include <iostream>
#include <string>
 
using namespace std;
int main()
{
    string input;
    cin >> input;
    int location[26];
    for(int i=0; i<26; i++){
        location[i] = -1;
    }
    for(int i=0; i<input.length(); i++){
        if(location[input[i]-'a'== -1){
            location[input[i]-'a'= i;
        }
    }
    
    for(int i=0; i<26; i++){
        cout << location[i] << ' ';
    }
    return 0;
}
 
 
cs

 

C++의 STL 중 하나인 string을 사용하면 손쉽게 해결할 수 있따.

반응형