egogoboy

"Часы"

Jun 3rd, 2022 (edited)
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. void update(int& hh1, int& mm1, int& ss1) {
  9.  
  10.     if (ss1 < 59) {
  11.         ss1++;
  12.     }
  13.     else if (mm1 < 59) {
  14.         mm1++;
  15.         ss1 = 0;
  16.     }
  17.     else if (hh1 < 23) {
  18.         hh1++;
  19.         mm1 = 0;
  20.         ss1 = 0;
  21.     }
  22.  
  23. }
  24. void count(int kk, vector<int>& m) {
  25.  
  26.     if (kk < 10) {
  27.         m[0]++;
  28.         m[kk % 10]++;
  29.     }
  30.     else {
  31.         m[kk / 10]++;
  32.         m[kk % 10]++;
  33.     }
  34.  
  35. }
  36.  
  37. int main() {
  38.  
  39.     std::ifstream fin("input.txt");
  40.     std::ofstream fout("output.txt");
  41.  
  42.     string time_1, time_2;
  43.  
  44.     fin >> time_1 >> time_2;
  45.  
  46.     int hh1 = stoi(time_1.substr(0, 2));
  47.     int hh2 = stoi(time_2.substr(0, 2));
  48.     int mm1 = stoi(time_1.substr(3, 2));
  49.     int mm2 = stoi(time_2.substr(3, 2));
  50.     int ss1 = stoi(time_1.substr(6, 2));
  51.     int ss2 = stoi(time_2.substr(6, 2));
  52.  
  53.     vector<int> m(10, 0);
  54.  
  55.     while (hh1 != hh2 || mm1 != mm2 || ss1 != ss2) {
  56.  
  57.         count(hh1, m);
  58.         count(mm1, m);
  59.         count(ss1, m);
  60.  
  61.         update(hh1, mm1, ss1);
  62.     }
  63.     count(hh1, m);
  64.     count(mm1, m);
  65.     count(ss1, m);
  66.  
  67.     for (int i = 0; i < 10; i++) {
  68.  
  69.         fout << m[i] << endl;
  70.  
  71.     }
  72.  
  73.     return 0;
  74.  
  75. }
Add Comment
Please, Sign In to add comment