[BaekJoon] 10178번 - 할로윈의 사탕 [Java][C++]
[BaekJoon] 10178번 - 할로윈의 사탕 [Java][C++]
1. 문제 풀이
사탕을 나누는 것은 몫으로, 남은 사탕은 나머지를 구하는 것으로 간단하게 구할 수 있다.
2. 코드
1. 풀이 [Java]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
StringTokenizer st;
int T = Integer.parseInt(br.readLine());
for (int tc = 1; tc <= T; tc++) {
st = new StringTokenizer(br.readLine());
int c = Integer.parseInt(st.nextToken());
int v = Integer.parseInt(st.nextToken());
sb.append("You get ").append(c / v).append(" piece(s) and your dad gets ").append(c % v).append(" piece(s).\n");
}
System.out.println(sb);
}
}
2. 풀이 [C++]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
for (int tc = 1; tc <= t; tc++) {
int c, v;
cin >> c >> v;
cout << "You get " << (c / v) << " piece(s) and your dad gets " << (c % v) << " piece(s).\n";
}
}
This post is licensed under CC BY 4.0 by the author.