C++ Algorithm/백준 알고리즘 문제 풀이
사칙연산 도전하기
3영2
2018. 11. 7. 14:18
반응형
10530번 문제 : 나머지
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include <iostream> using namespace std; int main() { int a, b; cin >> a >> b; double result = (double)a / (double)b; cout << fixed; cout.precision(9); cout << result << endl; return 0; } | cs |
10869번 문제 : 사칙연산
https://www.acmicpc.net/problem/10869
1 2 3 4 5 6 7 8 9 | #include <iostream> using namespace std; int main(void) { int a, b; cin >> a >> b; cout << a + b << endl << a - b << endl << a * b << endl << a / b << endl << a % b; return 0; } | cs |
10530번 문제 : 나머지
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #include <iostream> using namespace std; int main() { int x, y, z; cin >> x >> y >> z; cout << (x + y) % z << endl; cout << (x % z + y % z) % z << endl; cout << (x * y) % z << endl; cout << ((x % z) * (y % z)) % z << endl; return 0; } | cs |
2389번 문제: 설탕 배달
https://www.acmicpc.net/problem/2839
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #include <iostream> using namespace std; int main(void) { int threeKgNum, fiveKgNum, leastNum; bool isChanged = false; int input; cin >> input; fiveKgNum = input / 5; leastNum = input; while (fiveKgNum >= 0) { int leftover = input - fiveKgNum * 5; if (leftover % 3 == 0) { threeKgNum = leftover / 3; int totalNum = fiveKgNum + threeKgNum; if (totalNum <= leastNum) { isChanged = true; leastNum = totalNum; } } fiveKgNum--; if (fiveKgNum < 0 && isChanged == false) { leastNum = -1; } } cout << leastNum << endl; return 0; } | cs |
반응형