Algorithm/C++ - BOJ
BOJ/백준 - 4796 캠핑 C++
ㅇㅇ잉
2021. 2. 3. 16:00
연속하는 P일 중, L일 동안만 사용할 수 있으면
우선 V를 P로 나눠주고, 나머지도 변수로 따로 저장해준다.
L이 나머지보다 작으면 저장해놓은 나머지를, 나머지가 L보다 크다면 L을 더하여 출력해준다.
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
|
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
vector <int> v;
int main() {
//시간 줄이기
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int L, P, V;
int cnt = 0;
while (1) {
cin >> L >> P >> V;
if (!L && !P && !V)break;
int day = V/P;
int day2 = V % P;
int ans = 0;
if (day2 < L) {
ans = L * day + day2;
cout << "Case " << ++cnt << ": " << ans << '\n';
}
else {
ans = L * day + L;
cout << "Case " << ++cnt << ": " << ans << '\n';
}
}
return 0;
}
|
cs |