fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <time.h>
  4. using namespace std;
  5.  
  6. enum TIME_TABLE_TYPE {
  7. TT_LESSON,TT_SMALL_BREAK,TT_LONG_BREAK
  8. };
  9.  
  10. struct tm add_time(struct tm time1, struct tm time2);
  11. void print_time(struct tm timeinfo);
  12.  
  13. int main() {
  14. struct tm lesson_start;
  15. struct tm lesson_length;
  16. struct tm small_break;
  17. struct tm long_break;
  18.  
  19. // Init default values
  20. lesson_start.tm_hour = 8;
  21. lesson_start.tm_min = 45;
  22.  
  23. lesson_length.tm_hour = 0;
  24. lesson_length.tm_min = 45;
  25.  
  26. small_break.tm_hour = 0;
  27. small_break.tm_min = 30;
  28.  
  29. long_break.tm_hour = 0;
  30. long_break.tm_min = 45;
  31.  
  32. // Init time_table
  33. vector <int> time_table = {TT_LESSON,TT_SMALL_BREAK,TT_LESSON,TT_SMALL_BREAK,TT_LESSON,TT_SMALL_BREAK,TT_LESSON,
  34. TT_LONG_BREAK,TT_LESSON};
  35.  
  36. struct tm timeinfo = lesson_start;
  37.  
  38. for(vector<int>::iterator i = time_table.begin(); i != time_table.end(); i++) {
  39. if (*i == TT_LESSON) {
  40. print_time(timeinfo);
  41. timeinfo = add_time(timeinfo,lesson_length);
  42. print_time(timeinfo);
  43. } else if (*i == TT_SMALL_BREAK) {
  44. timeinfo = add_time(timeinfo,small_break);
  45. } else if (*i == TT_LONG_BREAK) {
  46. timeinfo = add_time(timeinfo,long_break);
  47. }
  48. }
  49.  
  50. return 0;
  51. }
  52.  
  53. void print_time(struct tm timeinfo) {
  54. cout << timeinfo.tm_hour << " : " << timeinfo.tm_min << endl;
  55. }
  56.  
  57. struct tm add_time(struct tm time1, struct tm time2) {
  58. time1.tm_hour +=time2.tm_hour;
  59. time1.tm_min += time2.tm_min;
  60. if (time1.tm_min >= 60) {
  61. time1.tm_hour = time1.tm_hour + 1;
  62. time1.tm_min -= 60;
  63. }
  64.  
  65. return time1;
  66. }
  67.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
8 : 45
9 : 30
10 : 0
10 : 45
11 : 15
12 : 0
12 : 30
13 : 15
14 : 0
14 : 45