[백준] 9093: 단어 뒤집기
2020. 12. 29. 05:21
Problem set
9093번: 단어 뒤집기 첫째 줄에 테스트 케이스의 개수 T가 주어진다. 각 테스트 케이스는 한 줄로 이루어져 있으며, 문장이 하나 주어진다. 단어의 길이는 최대 20, 문장의 길이는 최대 1000이다. 단어와 단어 사이에는 www.acmicpc.net #include #include #include int main() { using namespace std; ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t; cin >> t; cin.ignore(); while (t--) { string str; getline(cin, str); str += "\n"; stack s; for (char ch : str) { if (..
[백준] 9012: 괄호
2020. 12. 29. 05:19
Problem set
9012번: 괄호 괄호 문자열(Parenthesis String, PS)은 두 개의 괄호 기호인 ‘(’ 와 ‘)’ 만으로 구성되어 있는 문자열이다. 그 중에서 괄호의 모양이 바르게 구성된 문자열을 올바른 괄호 문자열(Valid PS, VPS)이라고 www.acmicpc.net #include #include #include using namespace std; string valid(const string& s) { int cnt = 0; for (int i = 0; i 0 && s[i] == ')') { cnt--; } else if (cnt > t; cin.ignore(); while (t-..
[백준] 8958: OX퀴즈
2020. 12. 29. 05:18
Problem set
8958번: OX퀴즈 "OOXXOXXOOO"와 같은 OX퀴즈의 결과가 있다. O는 문제를 맞은 것이고, X는 문제를 틀린 것이다. 문제를 맞은 경우 그 문제의 점수는 그 문제까지 연속된 O의 개수가 된다. 예를 들어, 10번 문제의 점수 www.acmicpc.net #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t; cin >> t; cin.ignore(); while (t--) { string str; getline(cin, str); str += "\n"; int cnt = 0; int score = 0; for (size..
[백준] 6588: 골드바흐의 추측
2020. 12. 29. 05:16
Problem set
6588번: 골드바흐의 추측 각 테스트 케이스에 대해서, n = a + b 형태로 출력한다. 이때, a와 b는 홀수 소수이다. 숫자와 연산자는 공백 하나로 구분되어져 있다. 만약, n을 만들 수 있는 방법이 여러 가지라면, b-a가 가장 큰 www.acmicpc.net #include using namespace std; const int MAX = 1000000; int prime[MAX]; int pn; bool check[MAX+1]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); for (int i = 2; i n; if (n == 0) { break; } for (int i = 1; i < pn; i++) { if (check..
[백준] 4673: 셀프넘버
2020. 12. 29. 05:15
Problem set
4673번: 셀프 넘버 셀프 넘버는 1949년 인도 수학자 D.R. Kaprekar가 이름 붙였다. 양의 정수 n에 대해서 d(n)을 n과 n의 각 자리수를 더하는 함수라고 정의하자. 예를 들어, d(75) = 75+7+5 = 87이다. 양의 정수 n이 주어졌을 때, www.acmicpc.net #include #include using namespace std; int d(const int& n) { int res = 0; int m = n; while (m > 0) { res = res + m % 10; m /= 10; } res += n; return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nu..
[백준] 3052: 나머지
2020. 12. 29. 03:58
Problem set
3052번: 나머지 각 수를 42로 나눈 나머지는 39, 40, 41, 0, 1, 2, 40, 41, 0, 1이다. 서로 다른 값은 6개가 있다. www.acmicpc.net #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int his[42] = {}; int input[10] = {}; for (size_t i = 0; i > input[i]; his[input[i] % 42]++; } int cnt = 0; for (int& n : his) { if (n != 0) { cnt++; } } cout
[백준] 2884: 알람 시계
2020. 12. 29. 02:21
Problem set
2884번: 알람 시계 상근이는 매일 아침 알람을 듣고 일어난다. 알람을 듣고 바로 일어나면 다행이겠지만, 항상 조금만 더 자려는 마음 때문에 매일 학교를 지각하고 있다. 상근이는 모든 방법을 동원해보았지만, www.acmicpc.net #include int main() { using namespace std; ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int hour, min; cin >> hour >> min; bool up = false, down = false; min = min - 45; if (min 60) { up = t..
[백준] 2588: 곱셈
2020. 12. 29. 02:00
Problem set
2588번: 곱셈 첫째 줄부터 넷째 줄까지 차례대로 (3), (4), (5), (6)에 들어갈 값을 출력한다. www.acmicpc.net #include int main() { using namespace std; ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int a, b; cin >> a >> b; int digit_1, digit_2, digit_3; digit_1 = b % 10; digit_2 = b % 100 - digit_1; digit_3 = b - digit_2-digit_1; cout