[백준] 1874: 스택 수열
2020. 12. 29. 01:48
Problem set
1874번: 스택 수열 1부터 n까지에 수에 대해 차례로 [push, push, push, push, pop, pop, push, push, pop, push, push, pop, pop, pop, pop, pop] 연산을 수행하면 수열 [4, 3, 6, 8, 7, 5, 2, 1]을 얻을 수 있다. www.acmicpc.net #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); stack stk; string hist; int n; cin >> n; int m = 0; while (n--) { int input; cin >..
[백준] 1676: 팩토리얼 0의 개수
2020. 12. 29. 01:46
Problem set
1676번: 팩토리얼 0의 개수 N!에서 뒤에서부터 처음 0이 아닌 숫자가 나올 때까지 0의 개수를 구하는 프로그램을 작성하시오. www.acmicpc.net #include using namespace std; int main() { int ans = 0; int n; cin >> n; for (int i=5; i
[백준] 1463: 1로 만들기
2020. 12. 29. 01:45
Problem set
1463번: 1로 만들기 첫째 줄에 1보다 크거나 같고, 106보다 작거나 같은 정수 N이 주어진다. www.acmicpc.net #include using namespace std; int d[1000001]; int main() { int n; cin >> n; d[1] = 0; for (int i=2; i d[i/2] + 1) { d[i] = d[i/2] + 1; } if (i%3 == 0 && d[i] > d[i/3] + 1) { d[i] = d[i/3] + 1; } } cout
[백준] 1406: 에디터
2020. 12. 29. 01:44
Problem set
1406번: 에디터 첫째 줄에는 초기에 편집기에 입력되어 있는 문자열이 주어진다. 이 문자열은 길이가 N이고, 영어 소문자로만 이루어져 있으며, 길이는 100,000을 넘지 않는다. 둘째 줄에는 입력할 명령어의 개수 www.acmicpc.net #include #include #include int main() { using namespace std; ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); string input_str; cin >> input_str; stack cursor_left, cursor_right; for (char& ch : input_str) { cursor_left.push(ch); } int t; ..
[백준] 1373: 2진수 8진수
2020. 12. 29. 01:42
Problem set
1373번: 2진수 8진수 첫째 줄에 2진수가 주어진다. 주어지는 수의 길이는 1,000,000을 넘지 않는다. www.acmicpc.net #include #include using namespace std; auto main()->int { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); string in; cin >> in; int n = in.size(); if (n % 3 == 1) { cout
[백준] 1212: 8진수 2진수
2020. 12. 29. 01:40
Problem set
1212번: 8진수 2진수 첫째 줄에 8진수가 주어진다. 주어지는 수의 길이는 333,334을 넘지 않는다. www.acmicpc.net #include #include #include using namespace std; string eight[8] = {"000","001","010","011","100","101","110","111"}; int main(){ string s; cin >> s; bool start = true; if (s.length() == 1 && s[0]-'0' == 0) { cout
[백준] 1158: 요세푸스 문제
2020. 12. 29. 01:38
Problem set
1158번: 요세푸스 문제 첫째 줄에 N과 K가 빈 칸을 사이에 두고 순서대로 주어진다. (1 ≤ K ≤ N ≤ 5,000) www.acmicpc.net #include #include using namespace std; int main() { int n, m; scanf("%d %d",&n,&m); queue q; for (int i=1; i
[백준] 1110: 더하기 사이클
2020. 12. 29. 01:36
Problem set
1110번: 더하기 사이클 0보다 크거나 같고, 99보다 작거나 같은 정수가 주어질 때 다음과 같은 연산을 할 수 있다. 먼저 주어진 수가 10보다 작다면 앞에 0을 붙여 두 자리 수로 만들고, 각 자리의 숫자를 더한다. 그 다음, www.acmicpc.net #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int ini_num; cin >> ini_num; int cnt = 0; int num; while (true){ if (cnt == 0) { num = ini_num; } int digit_1 = num % 10; int dig..