parkit
2019. 5. 11. 02:30
728x90
반응형
https://programmers.co.kr/learn/courses/30/lessons/17684
테스트 케이스가 잘 작동 되길래,
제출하였더니 한 번에 맞았다.
왜 맞지..?
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | #include <iostream> #include <deque> #include <list> #include <queue> #include <stack> #include <cstdio> #include <vector> #include <cstring> #include <string> #include <math.h> #include <algorithm> #include <map> #include <set> #pragma warning(disable:4996) #pragma comment(linker, "/STACK:336777216") using namespace std; map<string, int> m; int idx = 0; void init() { for (int i = 'A'; i <= 'Z'; i++) { string s; s = (char)i; m[s] = i - 'A' + 1; } } vector<int> solution(string msg) { vector<int> answer; idx = 27; init(); string s = ""; for (int i = 0; i < msg.length(); i++) { s += msg.at(i); // 있으면 if (m.count(s)) { string before; // 최대한 긴걸 찾는다 while (i < msg.length()) { if (!m.count(s)) { m[s] = idx++; answer.push_back(m[before]); s = ""; --i; break; } before = s; ++i; if (i >= msg.length()) { answer.push_back(m[before]); break; } s += msg.at(i); } } } return answer; } | cs |
728x90
반응형