코딩테스트/백준

    [실4] 1755 - 숫자놀이

    #include #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); const string numbers[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", }; vector ans; int n, m; cin >> n >> m; for (size_t i = n; i = 10) s = numbers[i / 10] + " " + numbers[i % 10]; else s = numbers[i % 10]; ans.push_back({ s,i ..

    [실5] 14916 - 거스름돈

    #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, res = 0; cin >> n; if (n < 5) res = (n % 2 == 0) ? n / 2 : -1; else { int q = n / 5; if (n % 5 == 0) res = q; else { int remain = n - q * 5; if (remain % 2 == 0) res = q + remain / 2; else res = (q - 1) + (remain + 5) / 2; } } cout

    [실4] 28278 - 스택 2

    #include #include #include using namespace std; stack s; string res; void Push(int n) { s.push(n); } void Pop() { if (s.empty()) res += to_string(-1) + '\n'; else { res += to_string(s.top()) + '\n'; s.pop(); } } void Size() { res += to_string(s.size()) + '\n'; } void Empty() { res += to_string(s.empty()) + '\n'; } void Top() { res += to_string(s.empty() ? -1 : s.top()) + '\n'; } int main() { ios..

    [실5] 2563 - 색종이

    #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int arr[100][100]{ 0 }; int n; cin >> n; for (size_t i = 0; i > n1 >> n2; for (size_t j = n1; j < n1 + 10; j++) { for (size_t k = n2; k < n2 + 10; k++) arr[j][k] = 1; } } int sum = 0; for (size_t i = 0; i < 100; i++) { for (size_t j = 0; j < 1..

    [실4] 10845 - 큐

    #include #include #include using namespace std; queue q; string res; void Push(int x) { q.push(x); } void Pop() { if (q.empty()) res += to_string(-1) + '\n'; else { res += to_string(q.front()) + '\n'; q.pop(); } } void Size() { res += to_string(q.size()) + '\n'; } void Empty() { res += to_string(q.empty() ? 1 : 0) + '\n'; } void Front() { res += to_string(q.empty() ? -1 : q.front()) + '\n'; } vo..

    [실4] 10816 - 숫자 카드 2

    #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; map data; for (int i = 0; i > val; data[val]++; } string s; int m; cin >> m; for (int i = 0; i > val; s += to_string(data[val]); if (i < m - 1) s += ' '; } cout

    [실4] 2003 - 수들의 합2

    #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m, s = 0, e = 0; cin >> n >> m; int* arr = new int[n]; for (int i = 0; i > arr[i]; int sum = 0, res = 0; while (e m) sum -= arr[s++]; else { res++; sum += arr[e++]; } } cout

    [골4] 1197 - 최소 스패닝 트리

    #include #include #include using namespace std; class Edge { public: int node[2]; int dist; Edge(int a, int b, int dist) { node[0] = a; node[1] = b; this->dist = dist; } bool operator> vertex >> edge; for (int i = 0; i > from >> to >> cost; v.push_back(Edge(from, to, cost)); } sort(v.begin(), v.end..

    [실1] 2468 - 안전 영역

    #include using namespace std; using IntPair = pair; #define MAX 100+1 #define y first #define x second IntPair dir[] { {1, 0}, // 상 {-1, 0}, // 하 {0, -1}, // 좌 {0, 1} // 우 }; int board[MAX][MAX]; bool vis[MAX][MAX]; int n, ans; void Reset() { for (int i = 0; i n) continue; if (!vis[ny][nx] && board[ny][nx] > rain) DFS(ny, nx, rain); } } void Input() { ios_base::sync_with_stdio(false); cin.tie(NU..

    [골4] 2580 - 스도쿠

    #include #define MAX 9 using namespace std; int map[MAX][MAX]; bool row[MAX][MAX]; bool col[MAX][MAX]; bool square[MAX][MAX]; void Input() { for (int i = 0; i > map[i][j]; auto val = map[i][j]; if (val != 0) { row[i][val] = col[j][val] = true; square[(i / 3) * 3 + (j / 3)][val] = true; } } } } void Print() { for (int i = 0; i < MAX; i++) { for (..