[백준] 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
[백준] 2557: 숫자의 개수
2020. 12. 29. 01:59
Problem set
2577번: 숫자의 개수 첫째 줄에 A, 둘째 줄에 B, 셋째 줄에 C가 주어진다. A, B, C는 모두 100보다 같거나 크고, 1,000보다 작은 자연수이다. www.acmicpc.net #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int a, b, c; cin >> a >> b >> c; int res = a * b * c; int his[10] = {}; int digit = 0; while (res > 0) { digit = res % 10; res /= 10; his[digit] +=1; } for (int& n : his) { cout
[백준] 2089: -2진수
2020. 12. 29. 01:56
Problem set
2089번: -2진수 -2진법은 부호 없는 2진수로 표현이 된다. 2진법에서는 20, 21, 22, 23이 표현 되지만 -2진법에서는 (-2)0 = 1, (-2)1 = -2, (-2)2 = 4, (-2)3 = -8을 표현한다. 10진수로 1부터 표현하자면 1, 110, 111, 100, 101, 11010, 110 www.acmicpc.net #include void go(int n) { if(n==0) { return; } if (n%2 == 0) { go(-(n/2)); printf("0"); } else { if (n > 0) { go(-(n/2)); } else { go((-n+1)/2); } printf("1"); } } int main(){ int n; scanf("%d\n",&n); if(n..
[백준] 1978: 소수 찾기
2020. 12. 29. 01:52
Problem set
1978번: 소수 찾기 첫 줄에 수의 개수 N이 주어진다. N은 100이하이다. 다음으로 N개의 수가 주어지는데 수는 1,000 이하의 자연수이다. www.acmicpc.net #include using namespace std; bool prime(int num) noexcept{ if (num > t; int result = 0; while (t--) { int num; cin >> num; if (prime(num)) { result++; } } cout
[백준] 1934: 최소공배수
2020. 12. 29. 01:51
Problem set
1934번: 최소공배수 두 자연수 A와 B에 대해서, A의 배수이면서 B의 배수인 자연수를 A와 B의 공배수라고 한다. 이런 공배수 중에서 가장 작은 수를 최소공배수라고 한다. 예를 들어, 6과 15의 공배수는 30, 60, 90등이 있 www.acmicpc.net #include using namespace std; //int gcd_1(int a, int b) { //int g = 1; //for (int i = 2; i < min(a, b); i++) { //if (a % i == 0 && b % i == 0) { //g = i; //} //} //return g; //} // //int gcd_2(int a, int b) { //if (b == 0) { return a; } //else { //g..
[백준] 1929: 소수 구하기
2020. 12. 29. 01:49
Problem set
1929번: 소수 구하기 첫째 줄에 자연수 M과 N이 빈 칸을 사이에 두고 주어진다. (1 ≤ M ≤ N ≤ 1,000,000) M이상 N이하의 소수가 하나 이상 있는 입력만 주어진다. www.acmicpc.net #include using namespace std; const int MAX = 1000000; bool check[MAX+1]; int main() { check[0] = check[1] = true; for (int i=2; i*i m >> n; for (int i=m; i