当前位置:   article > 正文

L2-042 老板的作息表_老板的作息表pta

老板的作息表pta

PTA | 程序设计类实验辅助教学平台 (pintia.cn)

  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. int arr[86400];
  5. int f(string s) {
  6. int a = stoi(s.substr(0, 2)) * 3600 + stoi(s.substr(3, 2)) * 60 + stoi(s.substr(6, 2));
  7. return a == 86399 ? 86400 : a;
  8. }
  9. void fun(string s1, string s2) {
  10. int a = f(s1);
  11. int b = f(s2);
  12. for (int i = a; i < b; i++) {
  13. arr[i] = 1;
  14. }
  15. return;
  16. }
  17. int find(int pos, int num) {
  18. while (pos < 86400) {
  19. if (arr[pos] == num) return pos;
  20. pos += 1;
  21. }
  22. return pos - 1;
  23. }
  24. void output(int a) {
  25. printf("%02d:%02d:%02d", a / 3600, a % 3600 / 60, a % 60);
  26. }
  27. int main() {
  28. int n;
  29. cin >> n;
  30. string s1, s2;
  31. for (int i = 0; i < n; i++) {
  32. cin >> s1 >> s2 >> s2;
  33. fun(s1, s2);
  34. }
  35. int a = 0, b = 0;
  36. while (a < 86399) {
  37. a = find(a, 0);
  38. b = find(a + 1, 1);
  39. if (arr[a]) break;
  40. output(a);
  41. cout << " " << "-" << " ";
  42. output(b);
  43. cout << endl;
  44. a = b + 1;
  45. }
  46. return 0;
  47. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/408572?site
推荐阅读
相关标签
  

闽ICP备14008679号