简单的时间转换,将当前时间减8h就是结果。
def convert_time(time_str):
h, m = map(int, time_str.split(':'))
total_min = h * 60 + m - 8 * 60
if total_min < 0:
total_min += 24 * 60
new_h = total_min // 60
new_m = total_min % 60
return f"{new_h:02d}:{new_m:02d}"
t = int(input().strip())
results = [convert_time(input().strip()) for _ in range(t)]
print('\n'.join(results))
import java.util.Scanner;
public class Main {
public static String convertTime(String timeStr) {
String[] parts = timeStr.split(":");
int h = Integer.parseInt(parts[0]);
int m = Integer.parseInt(parts[1]);
int totalMin = h * 60 + m - 8 * 60;
if (totalMin < 0) {
totalMin += 24 * 60;
}
int newH = totalMin / 60;
int newM = totalMin % 60;
return String.format("%02d:%02d", newH, newM);
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int t = scanner.nextInt();
scanner.nextLine();
String[] results = new String[t];
for (int i = 0; i < t; i++) {
String timeStr = scanner.nextLine();
results[i] = convertTime(timeStr);
}
for (String result : results) {
System.out.println(result);
}
}
}
#include <iostream>
#include <vector>
#include <cstdio>
#include <iomanip>
using namespace std;
string convertTime(const string& timeStr) {
int h, m;
sscanf(timeStr.c_str(), "%d:%d", &h, &m);
int totalMin = h * 60 + m - 8 * 60;
if (totalMin < 0) {
totalMin += 24 * 60;
}
int newH = totalMin / 60;
int newM = totalMin % 60;
char buffer[6];
snprintf(buffer, sizeof(buffer), "%02d:%02d", newH, newM);
return string(buffer);
}
int main() {
int t;
cin >> t;
vector<string> results(t);
string timeStr;
for (int i = 0; i < t; ++i) {
cin >> timeStr;
results[i] = convertTime(timeStr);
}
for (const auto& result : results) {
cout << result << endl;
}
return 0;
}
东八区(UTC/GMT+08:00)是比世界协调时间(UTC)/格林尼治时间(GMT)快8小时的时区,理论上的位置是东经112.5度至127.5度之间。在此15度的范围内,统一采用以东经120度中心线的地方时间为准。是东盟标准的其中一个候选时区。当格林尼治标准时间为00:00时东八区的标准时间为08:00。
每个测试文件均包含多组测试数据。第一行输入一个整数T(1<T<104)代表数据组数,每组测试数据描述如下:
在一行上输入一个格式为"小时:分钟"的北京时间(24小时制)
对于每一组测试数据,在一行上输出对应的世界协调时间,注意小时和分钟都应当补0至两位数。
输入:
2
8:30
00:00
输出:
00:30
16:00