解题思路:
就简单的把对应小时,分钟,秒分别相加;
如果分钟和秒大于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 人评分
C语言程序设计教程(第三版)课后习题6.10 (C语言代码)浏览:1090 |
C语言程序设计教程(第三版)课后习题6.5 (C语言代码)浏览:660 |
printf基础练习2 (C语言代码)浏览:690 |
printf基础练习2 (C语言代码)浏览:796 |
数对 (C语言代码)浏览:762 |
大家好,我是验题君浏览:604 |
图形输出 (C语言代码)浏览:1422 |
1118(求助_已解决)浏览:351 |
复数求和 (C语言代码)浏览:994 |
良心推荐——>题解1049:C语言程序设计教程(第三版)课后习题11.1 (C语言描述——简单明了,时间复杂度低)浏览:1318 |