tungggg

time

May 17th, 2022
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.47 KB | None | 0 0
  1. struct Time {
  2.     // your code goes here
  3.     // Cac bien thanh vien
  4.    
  5.     int h ;
  6.     int m ;
  7.     int s ;
  8.     // your code goes here
  9.     // Hai ham khoi tao
  10.    
  11.     Time (){
  12.         h=0 ;
  13.         m=0 ;
  14.         s =0 ;
  15.     }
  16.     Time ( int _h , int _m , int _s ){
  17.         h=_h ;
  18.          m=_m ;
  19.          s=_s;
  20.          
  21.     }
  22.    
  23.     int second() {
  24.         // your code goes here
  25.         int res  = s + m * 60 + h * 60 * 60 ;
  26.         return res ;
  27.        
  28.     }
  29.    
  30.     void print() {
  31.         // your code goes here
  32.        
  33.         string hourr =  string ( 2- to_string(h).size(),'0' ) + to_string(h);
  34.         string secc =  string ( 2- to_string(s).size(),'0' ) + to_string(s);
  35.         string minn = string ( 2- to_string(m).size(),'0' ) + to_string(m);
  36.         string res = hourr + ":" +minn + ":" + secc ;
  37.         cout << res << endl;
  38.        
  39.        
  40.     }
  41. };
  42.  
  43. Time normalize(int h, int m, int s) {
  44.     // your code goes here
  45.    
  46.     Time res ;
  47.     int realSec = s , realMin =m , realHour =h ;
  48.     if ( s>=60 ){
  49.         realSec =  s% 60 ;
  50.         realMin = m + s/60 ;
  51.     }
  52.    
  53.     if ( realMin >= 60 ){
  54.         realHour = h + realMin/60;
  55.         realMin = realMin % 60;
  56.        
  57.     }
  58.    
  59.     if ( realHour == 24 ){
  60.         realHour =0 ;
  61.     }
  62.     else if ( realHour > 24 ){
  63.         realHour = realHour - 24 ;
  64.     }
  65.     res.h = realHour ;
  66.     res.m = realMin ;
  67.     res.s = realSec;
  68.     return res;
  69.    
  70.    
  71.    
  72. }
Advertisement
Add Comment
Please, Sign In to add comment