QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#136696#245. Time Zonefreshmen#100 ✓82ms3636kbC++141.5kb2023-08-09 10:12:362023-08-09 10:12:38

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-09 10:12:38]
  • 评测
  • 测评结果:100
  • 用时:82ms
  • 内存:3636kb
  • [2023-08-09 10:12:36]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

struct TimE
{
	int h, s;
	TimE(int x, int y, int ind = 0)
	{
		if (ind == 0)
			h = x, s = y;
		else
			h = x, s = 60 * y / 10;
	}

	TimE operator +(TimE other)
	{
		int ns = other.s + s, nh = other.h + h;
		if (ns >= 60)
			ns -= 60, nh++;
		if (nh >= 24)
			nh -= 24;
		return (TimE) {nh, ns};
	}

	TimE operator -(TimE other)
	{
		int ns = s - other.s, nh = h - other.h;
		if (ns < 0)
			ns += 60, nh--;
		if (nh < 0)
			nh += 24;
		return (TimE) {nh, ns};
	}
};

void solve()
{
	int a, b;
	char ti[20];
	scanf("%d%d%s", &a, &b, ti);
	TimE ini(a, b);
	int th, ts = 0;
	if (isdigit(ti[5]))
		th = (ti[4]-'0') * 10 + ti[5]-'0';
	else
		th = ti[4]-'0';
	if (ti[5] == '.' || ti[6] == '.')
	{
		if (isdigit(ti[strlen(ti)-2]))
			ts = (ti[strlen(ti)-2]-'0') * 10 + ti[strlen(ti)-1]-'0';
		else
			ts = ti[strlen(ti)-1]-'0';
	}
	TimE utc(th, ts, 1);
	if (ti[3] == '+')
		ini = ini + utc;
	else
		ini = ini - utc;
	TimE u8(8, 0);
	ini = ini - u8;

	string hs, ss;
	if (ini.h == 0)
		hs = "00";
	else if (ini.h < 10)
		hs = "0", hs += (char)(ini.h+'0');
	else
		hs = (char)(ini.h/10+'0'), hs += (char)(ini.h%10+'0');
	if (ini.s == 0)
		ss = "00";
	else if (ini.s < 10)
		ss = "0", ss += (char)(ini.s+'0');
	else
		ss = (char)(ini.s/10+'0'), ss += (char)(ini.s%10+'0');
	printf("%s:%s\n", hs.c_str(), ss.c_str());
}

int main()
{
	int T;
	scanf("%d", &T);
	while (T--)
		solve();

	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 82ms
memory: 3636kb

input:

406080
0 0 UTC+0
0 0 UTC-0
0 0 UTC+0.1
0 0 UTC-0.1
0 0 UTC+0.2
0 0 UTC-0.2
0 0 UTC+0.3
0 0 UTC-0.3
0 0 UTC+0.4
0 0 UTC-0.4
0 0 UTC+0.5
0 0 UTC-0.5
0 0 UTC+0.6
0 0 UTC-0.6
0 0 UTC+0.7
0 0 UTC-0.7
0 0 UTC+0.8
0 0 UTC-0.8
0 0 UTC+0.9
0 0 UTC-0.9
0 0 UTC+1
0 0 UTC-1
0 0 UTC+1.1
0 0 UTC-1.1
0 0 UTC+1.2
0...

output:

16:00
16:00
16:06
15:54
16:12
15:48
16:18
15:42
16:24
15:36
16:30
15:30
16:36
15:24
16:42
15:18
16:48
15:12
16:54
15:06
17:00
15:00
17:06
14:54
17:12
14:48
17:18
14:42
17:24
14:36
17:30
14:30
17:36
14:24
17:42
14:18
17:48
14:12
17:54
14:06
18:00
14:00
18:06
13:54
18:12
13:48
18:18
13:42
18:24
13:36
...

result:

ok 406080 lines