-
10809) 알파벳 찾기 c++백준코딩일기 2020. 11. 23. 19:42
문제 ) www.acmicpc.net/problem/10809
풀이 )
1. 배열을 -1 로 초기화한다.
2. input[i] = char 형이 되는데, input[i] - 'a' 로 표기하면 숫자로 출력하게 되어서
arr 배열에 i 값을 넣어준다.3. 출력
코드 )
#include <iostream> using namespace std; string input; int arr[26]; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // 1 fill_n(arr, 26, -1); cin >> input; // 2 for(int i=0; i<input.length(); i++){ if(arr[input[i] - 'a'] == -1) arr[input[i] - 'a'] = i; } // 3 for(int i=0; i<26; i++) { cout << arr[i] << " "; } }
'백준코딩일기' 카테고리의 다른 글
2743) 단어 길이 재기 c++ (0) 2020.11.24 10820) 문자열 분석 c++ (0) 2020.11.24 17298) 오큰수 c++ (0) 2020.11.19 9093) 단어 뒤집기 c++ (0) 2020.11.19 4889) 안정적인 문자열 c++ (0) 2020.11.17