[알고리즘]/백준
자바 - 구현 - 백준 2460 지능형 기차2
broship
2021. 5. 3. 17:48
문제
문제해결
import java.util.Scanner;
public class B3_2460 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int human = 0;
int max = 0;
for (int i = 0; i < 10; i++) {
int out = sc.nextInt();
int in = sc.nextInt();
human -= out;
human += in;
if (human>max) max = human;
}
System.out.println(max);
}
}
- human변수를 만들어 기차안에 사람 수를 기록한다
- max 변수를 만들어 기차안에 사람수가 최대치일때를 기록해논다
- 10번 정류장까지 체크 후 max를 출력하면 된다.