Angwauh


私信TA

用户名:1710113018

访问量:32871

签 名:

你脚下曾踏过的泥沼,是你涤荡着强大的最好印证!

等  级
排  名 95
经  验 8465
参赛次数 6
文章发表 42
年  龄 19
在职情况 在职
学  校 河南农业大学
专  业 软件技术

  自我简介:


解题思路:

就简单的把对应小时,分钟,秒分别相加;

如果分钟和秒大于60的话,就像高位进;



注意事项:

再分别相加时,应先加秒,然后分钟,最后小时;(因为可能存在本来高位不足进位,但从低位进位一个后就满足了);

输出的顺序还有空格要求!



参考代码:

import java.util.Scanner;

public class Main{
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 1; i <= n; i++) {
			int ah = sc.nextInt(), am = sc.nextInt(), as = sc.nextInt();
			int bh = sc.nextInt(), bm = sc.nextInt(), bs = sc.nextInt();
			int cs = 0, cm = 0;
			int s = as + bs;
			if (s >= 60) {
				cs = s / 60;
				s = s % 60;
			}
			int m = am + bm + cs;
			if (m >= 60) {
				cm = m / 60;
				m = m % 60;
			}
			int h = ah + bh + cm;
			System.out.println(h + " " + m + " " + s);
		}
	}
}
 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区