Advertisement
Andrey_ZoZ

ChasMicolai

Sep 3rd, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. int main()
  4. {
  5.     int h1,m1,s1,h2,m2,s2;
  6.     char none;
  7.     std::cin>>h1>>none>>m1>>none>>s1;
  8.     std::cin>>h2>>none>>m2>>none>>s2;
  9.     h1=abs(h1);
  10.     h2=abs(h2);
  11.     m1=abs(m1);
  12.     m2=abs(m2);
  13.     s1=abs(s1);
  14.     s2=abs(s2);
  15.     int secondsOne=h1*60*60+m1*60+s1;
  16.     int secondsTwo=h2*60*60+m2*60+s2;
  17.     if(secondsOne>secondsTwo){std::swap(secondsOne,secondsTwo);}
  18.     secondsTwo-=secondsOne;
  19.     int minutesTotal=secondsTwo/60;
  20.     secondsTwo%=60;
  21.     int hoursTotal=minutesTotal/60;
  22.     minutesTotal%=60;
  23.     if (hoursTotal<10) {
  24.         std::cout<<"0"<<hoursTotal<<":";
  25.     }
  26.     else{std::cout<<hoursTotal<<":";}
  27.     if(minutesTotal<10){std::cout<<"0"<<minutesTotal<<":";}
  28.     else{std::cout<<minutesTotal<<":";}
  29.     if(secondsTwo<10){std::cout<<"0"<<secondsTwo;}
  30.     else{std::cout<<secondsTwo;}
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement