#include #include

using namespace std;

int timeDifference(string time1, string time2) { int hour1, minute1, second1; int hour2, minute2, second2;

stringstream ss1(time1), ss2(time2);
char delimeter;

ss1 >> hour1 >> delimeter >> minute1 >> delimeter >> second1;
ss2 >> hour2 >> delimeter >> minute2 >> delimeter >> second2;

int totalSeconds1 = hour1 * 3600 + minute1 * 60 + second1;
int totalSeconds2 = hour2 * 3600 + minute2 * 60 + second2;

return totalSeconds1 - totalSeconds2;

}

int main() { string time1, time2; getline(cin, time1); getline(cin, time2);

int difference = timeDifference(time1, time2);
cout << difference << endl;

return 0;

}

C++ 计算时间差 - GESP 三级编程题

原文地址: https://www.cveoy.top/t/topic/pgNu 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录