코딩테스트
[골3] 2812 - 크게 만들기
#include #include #include #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k; string str; vector v; cin >> n >> k >> str; for (int i = 0; i 0 && !v.empty() && v.back() < str[i]) { v.pop_back(); k--; } v.push_back(str[i]); } while (k--) v.pop_back(); for (int i = 0; i < v.size(); i..
[플5] 16496 - 큰 수 만들기
정렬 함수 3번째 인자 _Pred 람다 함수로 깔끔하게 해결 #include #include #include #include #include using namespace std; #define SIZE 1000 int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string arr[SIZE]; int n; cin >> n; cin.ignore(); int flag = 0; for (int i = 0; i > arr[i]; if (arr[i] != "0") flag = true; } if (!flag) cout str2 + str1; }); cout
[실1] 2583 - 영역 구하기 bfs
#include #include #include #include #include using namespace std; using int_pair = pair; #define SIZE 1000 #define x first #define y second // 상 하 좌 우 int_pair arr_pos[] { {0, 1}, {0,-1}, {-1,0}, {1, 0} }; queue q; bool graph[SIZE][SIZE]{ false }; int zone = 0; // w:넓이, h:높이, k:테스트 개수 int w, h, k; int BFS() { int block_cnt = 0; while (!q.empty()) { auto front = q.front(); q.pop(); for (int i = 0..
C++ 문자열 공백 제거하는 방법
#include #include #include #include #include #include #include #include using namespace std; int main() { string str = "Hello World!"; string str2 = str, str3 = str; cout
[실1] 14888 - 연산자 끼워넣기
#include using namespace std; #define OPERATOR_COUNT 4 int n; int arr_operand[1000]; // 수열 int arr_operator[OPERATOR_COUNT]; int min_val = INT_MAX; int max_val = INT_MIN; void DFS(int result, int idx) { if (idx == n) { if (result > max_val) max_val = result; if (result 0) { arr_operator[i]--; ..
[실1] 11403 - 경로 찾기
플로이드 와샬 #include #define INF 100000 #define NODE 1000 using namespace std; int graph[NODE][NODE]{ 0 }; void Floyd_washall() { int n; cin >> n; for (int i = 0; i > graph[i][j]; } for (int k = 0; k < n; k++) // 거쳐가는 노드 { for (int i = 0; i < n; i++) // 출발지 노드 { for (int j = 0; j < n; j++) // 도착지 노드 { if (graph[i][k] && graph[k][j]) graph[i][j]= 1; } } } ..
컴파일 속도 향상 (시간 초과 오류)와 Stream (스트림)
ios::sync_with_stdio, cin.tie, cout.tie란? ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); Stream 우선 stream에 대한 이해가 먼저 필요하다 우리가 c언어와 c++언어를 가장 처음 배울 때 적는 것은 사실 아래에 두 헤더파일이다 각각은 stdio: standard input output iostream: input output stream #include #include 표준 스트림(standard streams)은 특정한 프로그래밍 언어 인터페이스뿐 아니라 유닉스 및 유닉스 계열 운영 체제(어느 정도까지는 윈도에도 해당함)에서 컴퓨터 프로그램과 그 환경(일반적으로 단말기) 사이에 미리 연결된 입출력 통로를 가리킨다. 우리..
[실1] 11286 - 절대값 힙
#include #include #include #include using namespace std; #define y first #define x second int main() { using pq_type = pair; cin.sync_with_stdio(0); cin.tie(0); priority_queue q; int n; cin >> n; for (int i = 0; i > val; if (val != 0) q.push({ abs(val), val }); else { if (q.empty()) cout
[실1] 1991 - 트리 순회
#include using namespace std; int n; struct node { char left; char right; }; struct node tree[100]; void preOrder(char root) { if (root == '.') return; else { cout t1 >> t2 >> t3; tree[t1].left = t2; tree[t1].right = t3; } preOrder('A'); cout left); cout data; In_order(_node->right); } // (왼쪽, 오른쪽, 루트) void Post_order(s_node* _node) { if (!_node) return; Post_order(_node->left); Post_order(_node..