Make Unreal REAL.
article thumbnail
vector::resize()

지정한 크기만큼 남은 공간을 특정 값으로 채우는 데 사용할 수 있다. #include #include using namespace std; void print(vector& v); void main() { vector v = {1, 2, 3, 4, 5}; v.resize(10, -1); print(v); } 출력 1 2 3 4 5 -1 -1 -1 -1 -1

article thumbnail
Level 0. 날짜 비교하기

Level 0. 날짜 비교하기 #include #include using namespace std; int solution(vector date1, vector date2) { if (date1[0] date2[0]) { return 0; } else if (date1[1] date2[1]) { return 0; } else if (date1[2] < date2[2]) { return 1; } else { return 0; } } 총 일수를 계산해 비교해도 된다. 크기만을 비교하므로, 모든 달의 일수를 31일로 계산해도 상관 없다. #incl..

article thumbnail
Level 0. 이차원 배열 대각선 순회하기

Level 0. 이차원 배열 대각선 순회하기 범위만 넘어가지 않게 조심하면 된다. #include #include #include using namespace std; int solution(vector board, int k) { int answer = 0; int row = board.size(), col = board.front().size(); ++k; for (int i = 0; i < row && i < k; ++i) { int c = (col

article thumbnail
Level 0. 조건에 맞게 수열 변환하기 2

Level 0. 조건에 맞게 수열 변환하기 2 vector는 비교 연산을 지원하며, 크기가 달라도 가능하다. #include #include #include using namespace std; int solution(vector arr) { int answer = -1; vector prev; while (prev != arr) { prev = arr; ++answer; for_each(arr.begin(), arr.end(), [](int& e) { if (50 >= 1; else if (e < 50 && e & 1) (e

article thumbnail
Level 0. 정사각형으로 만들기

Level 0. 정사각형으로 만들기 #include #include #include using namespace std; vector solution(vector arr) { int row = arr.size(), col = arr.front().size(); if (row col) { for_each(arr.begin(), arr.end(), [&](vector& v) { v.resize(row); fill(v.begin() + col, v.end(), 0); }); } return arr; }

article thumbnail
Level 0. 배열의 길이를 2의 거듭제곱으로 만들기

Level 0. 배열의 길이를 2의 거듭제곱으로 만들기 #include #include #include using namespace std; vector solution(vector arr) { size_t o_size = arr.size(); size_t new_size = 0b1; while (new_size < o_size) new_size

검색 태그