解题思路:先用时间的进制算出想对应的时间,然后通过变换成字符串进行格式调整,达到HH:MM:SS的格式,喜欢java解题可以看看我的解法
注意事项:
参考代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int H = 0;
int M = 0;
int S = 0;
int[] backup = new int[n];
for (int i = 0; i < n; i++) {
backup[i] = sc.nextInt();
}
String HH = "";
String MM = "";
String SS = "";
for (int i = 0; i < n; i++) {
H = backup[i] / 3600;
backup[i] -= H * 3600;
if (H / 10 == 0) {
HH = "0" + H;
} else {
HH = H + "";
}
M = backup[i] / 60;
backup[i] -= M * 60;
if (M / 10 == 0) {
MM = "0" + M;
} else {
MM = M + "";
}
S = backup[i];
if (S / 10 == 0) {
SS = "0" + S;
} else {
SS = S + "";
}
System.out.println(HH + ":" + MM + ":" + SS);
}
}
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题8.9 (C语言代码)浏览:1763 |
C语言训练-邮票组合问题* (C语言代码)......浏览:689 |
输出九九乘法表 (C语言代码)浏览:583 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:1092 |
九宫重排 (C++代码)浏览:1410 |
C语言程序设计教程(第三版)课后习题11.5 (C语言代码)浏览:932 |
分糖果 (C++代码)浏览:1537 |
拆分位数 (C语言代码)浏览:1361 |
C语言程序设计教程(第三版)课后习题6.2 (C语言代码)浏览:1432 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:1110 |