Skip to content

Instantly share code, notes, and snippets.

@tabvn
Created November 1, 2018 04:42
Show Gist options
  • Select an option

  • Save tabvn/4e474cf7f934e39fe713608d78b90f63 to your computer and use it in GitHub Desktop.

Select an option

Save tabvn/4e474cf7f934e39fe713608d78b90f63 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
struct Time
{
int h,m,s;
};
Time t1,t2;
Time sum(Time a, Time b){
// cong giay
Time c;
// reset mac dinh ve 0:0:0
c.s = 0;
c.m = 0;
c.h = 0;
// tien hanh cong giay
c.s = a.s +b.s;
if(c.s >=60){
int increMinue = c.s/60;
c.s = c.s - (increMinue * 60);
// tang so phut
c.m = c.m + increMinue;
}
// cong phut
c.m = c.m + (a.m + b.m);
if(c.m >= 60){
int increasehour = c.m / 60;
c.m = c.m - (60*increasehour);
c.h = c.h + increasehour;
}
// hour
c.h = c.h + a.h + b.h;
if(c.h >=24){
c.h = c.h - ((c.h/24) * 24);
}
return c;
}
int main(){
t1.h = 12;
t1.m = 59;
t1.s = 30;
t2.h = 15;
t2.m = 0;
t2.s = 30;
// tinh t1 + t2
Time s = sum(t1, t2);
cout << t1.h <<":" << t1.m<< ":" << t1.s<< "+" << t2.h <<":" << t2.m<< ":" << t2.s<< endl;
cout << s.h <<":" << s.m<< ":" << s.s;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment