[백준] 10430: 나머지
2020. 12. 29. 05:26
Problem set
10430번: 나머지 첫째 줄에 A, B, C가 순서대로 주어진다. (2 ≤ A, B, C ≤ 10000) www.acmicpc.net #include using namespace std; auto main()->int { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int a, b, c; cin >> a >> b >> c; cout
[백준] 9613: GCD 합
2020. 12. 29. 05:24
Problem set
9613번: GCD 합 첫째 줄에 테스트 케이스의 개수 t (1 ≤ t ≤ 100)이 주어진다. 각 테스트 케이스는 한 줄로 이루어져 있다. 각 테스트 케이스는 수의 개수 n (1 int { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); unsigned int t = 0; cin >> t; while (t--) { ..
[백준] 9095: 1, 2, 3 더하기
2020. 12. 29. 05:22
Problem set
9095번: 1, 2, 3 더하기 각 테스트 케이스마다, n을 1, 2, 3의 합으로 나타내는 방법의 수를 출력한다. www.acmicpc.net #include using namespace std; int d[11]; void cal() { d[0] = 1; for (int i = 1; i = 1) { d[i] += d[i - 1]; } if (i >= 2) { d[i] += d[i - 2]; } if (i >= 3) { d[i] += d[i - 3]; } } } auto main()->int { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cal(); int t; cin >> t; w..
[백준] 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..