[ 단축키 지정 방법 ]
1. 하나의 옵션에 대해 왼쪽 → 오른쪽 순서로 단어의 첫 글자가 이미 단축키로 지정되었는지 확인 단축키로 지정되어있지 않은 경우 단축키로 지정
2. 만약 모든 단어의 첫 글자가 이미 지정 되어있다면 왼쪽에서 차례대로 알파벳을 보면서 단축키로 안 된 것 단축키로 지정
3. 단축키로 지정할 수 있는 것이 없을 경우 그냥 놔둔다. (대소문자 구분 X)
4. 위의 규칙을 첫 번째 옵션부터 N번째 옵션까지 차례대로 적용
" " 위치 + 1
한 위치로 찾기#include <iostream> #include <string> #include <map> using namespace std; int main() { int N; cin >> N; cin.ignore(); map <char, int> list; for(int i=0; i<N; i++) { string option; getline(cin, option); int idx = 0; int check = 0; while(!check) { if(list.find(tolower(option[idx])) == list.end()) { list.insert(make_pair(tolower(option[idx]), 1)); string str = "["; str += option[idx]; option.replace(idx, 1, str.append("]")); check = 1; } // 다음 단어 위치 찾기 idx = option.find(" ", idx); if(idx == string::npos) break; idx++; } if(!check) { for(int j=0; j<option.length(); j++) { if(option[j] == ' ') continue; if(list.find(tolower(option[j])) == list.end()) { list.insert(make_pair(tolower(option[j]), 1)); string str = "["; str += option[j]; option.replace(j, 1, str.append("]")); break; } } } cout << option << "\n"; } return 0; }
// insert 사용 option.insert(idx, "["); option.insert(idx + 2, "]"); // string 사용 string keyword = "[" + string(1, option[idx]) + "]"; option.replace(idx, 1, keyword);
cin.ignore()
를 통해 입력 버퍼 비워주기 !