풀이는 아래와 같다.
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을 사용하면 손쉽게 해결할 수 있따.
반응형
'Baekjoon(C++)' 카테고리의 다른 글
[C++]백준 알고리즘 2908번 (0) | 2021.07.14 |
---|---|
[C++]백준 알고리즘 1157번 (0) | 2021.07.14 |
[C++]백준 알고리즘 19532번 (0) | 2021.07.11 |
[C++]백준 알고리즘 1463번 (0) | 2021.07.11 |
[C++]백준 알고리즘 2246번 (2) | 2021.07.04 |