![article thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FwpdOd%2FbtsepJSpJd3%2F1NufdhbwmforgwzKI7xtKK%2Fimg.png)
Level 0. 코드 처리하기 #include using namespace std; string solution(string code) { bool mode = false; size_t len = code.length(); string answer; for (int i = 0; i < len; ++i) if (code[i] == '1') mode = !mode; else if ( (i & 1) == (mode ? 1 : 0) ) answer += code[i]; return answer.empty() ? "EMPTY" : answer; }
![article thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbX6srJ%2FbtsejKWkL8j%2Fb7o8bcs1xyhBkG0nQRdZdK%2Fimg.png)
Level 2. [1차] 프렌즈4블록 솔직히 이번 건 좀 어려웠다. 2 * 2 크기를 확인해야 하므로, 2차원 벡터에 1칸씩 여유 공간이 더 필요했다. 2차원 벡터의 원소들을 -Y 방향으로 내려야 하다보니 생각하기가 쉽지 않았다. 그래서 벡터를 돌리면 된다는 걸 깨달았다. 근데 이것도 처음에 블록들을 내리나, 올리나 똑같다고 잘못 생각해 헛수고를 했다. unordered_set에 pair 타입을 쓸 수가 없어, XXXYYY 6자리의 int에 X, Y 정보를 담아 삽입했다. 인덱스를 가져올 때는 다시 나누고 나머지 연산을 쓰면 된다. 또, remove() 함수 때문에도 애를 먹었다. unique() 함수와 같이 지운 원소들을 뒤로 보내는 줄 알았는데, 그게 아니라 뒤에는 그냥 쓰레기 값으로 채워져 있어 f..
![article thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbAnBTF%2Fbtsd0o2su2f%2FBz71JeyDb8bzjylOoQU4S1%2Fimg.png)
vector에 unique(), remove() 함수를 적용해도 실행 전후의 크기는 같다. unique() 함수와 remove() 함수 모두 크기는 동일하지만, 필요 없는 값으로 채워지기 시작하는 반복자 위치를 반환한다. #include #include #include using namespace std; void print(vector& v); int main() { vector v1 = {1, 1, 2, 2, 3, 3, 4, 5, 6}; vector v2(v1); unique(v1.begin(), v1.end()); print(v1); remove(v2.begin(), v2.end(), 2); print(v2); } 출력 1 2 3 4 5 6 4 5 6 ^ 1 1 3 3 4 5 6 5 6 ^
![article thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FbJ0tOX%2Fbtsd6t102Ef%2FMLRwpJnfkCqDckFocPPXv1%2Fimg.png)
Level 2. 삼각 달팽이 한 방향당 n, n-1, n-2, ..., 1, 0 개수대로 입력하면 된다. 피라미드 모양으로 생각하지 말고, 직각삼각형 모양으로 생각하면 쉽다. 1 2 9 3 10 8 4 5 6 7 #include #include using namespace std; vector solution(int n) { vector answer((n + 1) * n / 2); vector vv(n, vector(n, -1)); int dx[] = {0, 1, -1}; int dy[] = {1, 0, -1}; int num = 1, dcur = 0; int x = 0, y = -1; do { for (int i = 0; i < n; ++i) vv[y += dy[dcur]][x += dx[dcur]] ..
![article thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FJzl6W%2FbtsdZZAz505%2FfnJnkpx6xn3cky4dh837OK%2Fimg.png)
Level 0. 배열 조각하기 #include #include using namespace std; vector solution(vector arr, vector query) { size_t size = query.size(); for (int i = 0; i < size; ++i) if (i & 1) arr.erase(arr.begin(), arr.begin() + query[i]); else arr.erase(arr.begin() + ++query[i], arr.end()); return arr; }
![article thumbnail](https://img1.daumcdn.net/thumb/R750x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FczMzEw%2FbtsdYCT2WJ4%2Ftusml2VdMVKOqdXsLLB5u0%2Fimg.png)
Level 0. 주사위 게임 3 map을 사용하면 가장 작은 첫 번째 원소를 바로 가져올 수 있다. #include #include #include using namespace std; int solution(int a, int b, int c, int d) { int answer = 1; map mp; ++mp[a], ++mp[b], ++mp[c], ++mp[d]; switch (mp.size()) { case 1: answer = 1111 * a; break; case 2: if (mp.begin()->second == 2) answer = (mp.begin()->first + mp.rbegin()->first) * abs(mp.begin()->first - mp.rbegin()->first); el..