Java洛谷P1425 小鱼的游泳时间

Java洛谷P1425 小鱼的游泳时间_第1张图片

题目链接:https://www.luogu.com.cn/problem/P1425

代码实例:


import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
		int d = scanner.nextInt();
		
		int e = c-a;
		int f = d-b;
		if(f<0) {
			e = c-a-1;
			f = d-b+60;
		}
		System.out.println(e+" "+f);
		scanner.close();

	}
}

注意,我们要考虑d-b<0的时候

你可能感兴趣的:(洛谷)