AT_abc001_4里说RE,听取WA声一片
查看原帖
AT_abc001_4里说RE,听取WA声一片
1284034
__lihaoyu68__楼主2024/7/8 11:37
#include <bits/stdc++.h>
using namespace std;
const int N = 3e4 + 5;
int i, cnt = 1, n;
string s;
struct str {
	string st, ed;
} t[N];
vector <str> ans;
inline bool cmp(str x, str y) {
	if (x.st != y.st)  return x.st < y.st;
	return x.ed < y.ed;
}
int main() {
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		cin >> s;
		t[i].st = s.substr(0, 4), t[i].ed = s.substr(5, 4);
		if (t[i].st[3] >= '5') t[i].st[3] = '5';
		else t[i].st[3] = '0';
		if (t[i].ed[3] <= '5') { if (t[i].ed[3] != '0') t[i].ed[3] = '5';}
		else t[i].ed[3] = '0', t[i].ed[2]++;
		if (t[i].ed[2] == '6' && t[i].ed[3] == '0') {
			if (t[i].ed[1] == '9') t[i].ed[1] = '0', t[i].ed[0]++;
			else t[i].ed[1]++;
			t[i].ed[2] = t[i].ed[3] = '0';
		}
	}
	sort(t + 1, t + n + 1, cmp);
	ans.resize(N); ans[1] = t[1];
	for (i = 2; i <= n; i++) {
		if (t[i].st <= ans[cnt].ed) ans[cnt].ed = max(ans[cnt].ed, t[i].ed);
		else ans[++cnt] = t[i];
	}
	for (i = 1; i <= cnt; i++)  printf("%s-%s\n", ans[i].st, ans[i].ed);
	return 0;
}
2024/7/8 11:37
加载中...