赞
踩
PTA | 程序设计类实验辅助教学平台 (pintia.cn)
- #include <iostream>
- #include <string>
- using namespace std;
-
- int arr[86400];
- int f(string s) {
- int a = stoi(s.substr(0, 2)) * 3600 + stoi(s.substr(3, 2)) * 60 + stoi(s.substr(6, 2));
- return a == 86399 ? 86400 : a;
- }
- void fun(string s1, string s2) {
- int a = f(s1);
- int b = f(s2);
- for (int i = a; i < b; i++) {
- arr[i] = 1;
- }
- return;
- }
- int find(int pos, int num) {
- while (pos < 86400) {
- if (arr[pos] == num) return pos;
- pos += 1;
- }
- return pos - 1;
- }
- void output(int a) {
- printf("%02d:%02d:%02d", a / 3600, a % 3600 / 60, a % 60);
- }
- int main() {
- int n;
- cin >> n;
- string s1, s2;
- for (int i = 0; i < n; i++) {
- cin >> s1 >> s2 >> s2;
- fun(s1, s2);
- }
- int a = 0, b = 0;
- while (a < 86399) {
- a = find(a, 0);
- b = find(a + 1, 1);
- if (arr[a]) break;
- output(a);
- cout << " " << "-" << " ";
- output(b);
- cout << endl;
- a = b + 1;
- }
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。