SHARE
TWEET

lab3zad1.cpp

michalkowalczyk Mar 19th, 2019 54 in 150 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include"functions.h"
  2.  
  3.  
  4.  
  5.  
  6.  int ToMinutes(string time_HH_MM)
  7. {
  8.  
  9.  
  10.  
  11.     regex search{"((\\d{1,2})[.:-]([0-5]\\d{1}))"}; // digit, separator, digit
  12.     smatch matched;
  13.     string string_hours, string_minutes;
  14.      int hours,minutes;
  15.     hours = minutes =0;
  16.  
  17.  
  18.     if(regex_match(time_HH_MM,matched,search)){
  19.  
  20.     string_hours=matched[2];
  21.     string_minutes=matched[3];
  22.  
  23.  
  24.     }
  25.     else {
  26.         cout<<"Input data error"<<endl;
  27.         return -1;
  28.     }
  29.  
  30.  
  31.     istringstream isminutes(string_minutes);
  32.     isminutes>>minutes;
  33.  
  34.  
  35.     istringstream ishours(string_hours);
  36.     ishours>>hours;
  37.  
  38.  
  39.  
  40.     return minutes + (60*hours);
  41. }
  42. unsigned int MinimalTimeDifference(vector<string> times){
  43.  
  44.     unsigned int minimum=UINT_MAX, tmp;
  45.     vector<int> time_in_minute;
  46.  
  47.     for (string i : times) {
  48.         int check = ToMinutes(i);
  49.         if(check<0)
  50.             continue;
  51.         else
  52.             time_in_minute.push_back(check);
  53.  
  54.     }
  55.     int i=1;
  56.  
  57.     vector<int>::iterator it1,it2;
  58.     for(it1=time_in_minute.begin();it1!=time_in_minute.end()-1;it1++){
  59.         for(it2=time_in_minute.begin()+i;it2!=time_in_minute.end();it2++){
  60.  
  61.             tmp = static_cast<unsigned int>( fabs(*it1-*it2));
  62.  
  63.  
  64.  
  65.  
  66.             if(tmp<minimum)
  67.                 minimum=tmp;
  68.  
  69.  
  70.  
  71.         }
  72.         i++; //not to compare the same times, because results is 0
  73.     }
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.     return minimum;
  83. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top