PAT 乙级 1026

 1 #include <iostream>
 2 using namespace std;
 3 
 4 const int CLK_TCK = 100;
 5 
 6 void out(int x) {
 7     if (x >= 10)
 8         cout << x;
 9     else if (x < 10 && x != 0)
10         cout << "0" << x;
11     else
12         cout << "00";
13 }
14 
15 int main() {
16     float c1 = 0, c2 = 0;
17     cin >> c1 >> c2;
18     float time = (c2 - c1) / CLK_TCK + 0.5;
19     int T = time;
20     int h = 0, m = 0, s = 0;
21     h = T / 3600;
22     m = (T - h * 3600) / 60;
23     s = T - h * 3600 - m * 60;
24 
25     out(h);
26     cout << ":";
27     out(m);
28     cout << ":";
29     out(s);
30     cout << endl;
31 
32     return 0;
33 }

猜你喜欢

转载自www.cnblogs.com/moujun1001/p/9453003.html