문제
https://www.acmicpc.net/problem/22864
22864번: 피로도
첫 번째 줄에 네 정수 $A$, $B$, $C$, $M$이 공백으로 구분되어 주어진다. 맨 처음 피로도는 0이다.
www.acmicpc.net
import java.util.Scanner;
public class Main22864 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int A = sc.nextInt();
int B = sc.nextInt();
int C = sc.nextInt();
int M = sc.nextInt();
sc.close();
int count = 0;
int work = 0;
for (int i=0; i<24; i++) {
if (count+A>M) {
count -= C;
if (count < 0) {
count = 0;
}
} else if (count<=M) {
count += A;
work += B;
}
}
System.out.println(work);
}
}
1. 첫번째 조건문 조건식에서 다소 헤맸지만 어렵지않게 풀었다.
'백준' 카테고리의 다른 글
백준 2661번 ☆ (0) | 2022.11.15 |
---|---|
백준 1969번 ☆ (0) | 2022.11.15 |
백준 19532번 (0) | 2022.11.10 |
백준 2231번 (0) | 2022.11.09 |
백준 14889번 (0) | 2022.11.08 |