资源限制
时间限制:1.0s 内存限制:512.0MB
问题描述
给定一个t,将t秒转化为HH:MM:SS的形式,表示HH小时MM分钟SS秒。HH,MM,SS均是两位数,如果小于10用0补到两位。
输入格式
第一行一个数T(1<=T<=100,000),表示数据组数。后面每组数据读入一个数t,0<=t<246060。
输出格式
每组数据一行,HH:MM:SS。
样例输入
2
0
86399
样例输出
00:00:00
23:59:59
Scanner输入超时!!!借鉴了别人的java输入挂 替代Scanner
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws Exception {
// Scanner sc = new Scanner(System.in);
InputReader sc = new InputReader(System.in);
int n = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; ++i) {
arr[i] = sc.nextInt();
}
// sc.close();
for (int i = 0; i < n; ++i) {
f(arr[i]);
}
}
public static void f(int x) {
StringBuilder sb = new StringBuilder();
if (x >= 3600) {
int h = x / 3600;
if (h >= 10) {
sb.append(h).append(":");
} else {
sb.append("0").append(h).append(":");
}
x = x - h * 3600;
int m = x / 60;
if (m >= 10) {
sb.append(m).append(":");
} else {
sb.append("0").append(m).append(":");
}
int s = x % 60;
if (s >= 10) {
sb.append(s);
} else {
sb.append("0").append(s);
}
} else if (x >= 60){
sb.append("00:");
int m = x / 60;
if (m >= 10) {
sb.append(m).append(":");
} else {
sb.append("0").append(m).append(":");
}
int s = x % 60;
if (s >= 10) {
sb.append(s);
} else {
sb.append("0").append(s);
}
} else {
sb.append("00:00:");
if (x >= 10) {
sb.append(x);
} else {
sb.append("0").append(x);
}
}
System.out.println(sb.toString());
}
}
//java输入挂 替代Scanner
class InputReader {
private BufferedReader reader;
private StringTokenizer tokenizer;
InputReader(InputStream in) {
reader = new BufferedReader(new InputStreamReader(in));
tokenizer = new StringTokenizer("");
}
public String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
public Integer nextInt() throws IOException {
return Integer.parseInt(next());
}
}