[백준] 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
[백준] 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