Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- int main()
- {
- int h1,m1,s1,h2,m2,s2;
- char none;
- std::cin>>h1>>none>>m1>>none>>s1;
- std::cin>>h2>>none>>m2>>none>>s2;
- h1=abs(h1);
- h2=abs(h2);
- m1=abs(m1);
- m2=abs(m2);
- s1=abs(s1);
- s2=abs(s2);
- int secondsOne=h1*60*60+m1*60+s1;
- int secondsTwo=h2*60*60+m2*60+s2;
- if(secondsOne>secondsTwo){std::swap(secondsOne,secondsTwo);}
- secondsTwo-=secondsOne;
- int minutesTotal=secondsTwo/60;
- secondsTwo%=60;
- int hoursTotal=minutesTotal/60;
- minutesTotal%=60;
- if (hoursTotal<10) {
- std::cout<<"0"<<hoursTotal<<":";
- }
- else{std::cout<<hoursTotal<<":";}
- if(minutesTotal<10){std::cout<<"0"<<minutesTotal<<":";}
- else{std::cout<<minutesTotal<<":";}
- if(secondsTwo<10){std::cout<<"0"<<secondsTwo;}
- else{std::cout<<secondsTwo;}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement