通过这道题 学会sscanf 和printf,scanf的基本用法,要学会包容,不能只待在c++舒适区,学会吸收c的一些精华
#include
using namespace std;
// 这道题我下定了决心学scanf和printf,要学会走出舒适区
int get_seconds(int h,int m,int s)
{
return h*3600+m*60+s;
}
int get_time()
{
string line;
getline(cin,line);
if(line.back()!=')') line+=" (+0)"; // 为了接下来处理规范
int h1,m1,s1,h2,m2,s2,d;
sscanf(line.c_str(),"%d:%d:%d %d:%d:%d (+%d)",&h1,&m1,&s1,&h2,&m2,&s2,&d); // 这是sscanf可以学习下,要是c++写会很麻烦
return get_seconds(h2,m2,s2)-get_seconds(h1,m1,s1)+d*3600*24;
}
int main()
{
int n;
scanf("%d",&n); // 好好学习下scanf
getchar(); // 读入第一行的换行符
while(n--)
{
int time=(get_time()+get_time())/2;
int hour=time/3600;
int minute=time%3600/60;
int second=time%60;
printf("%02d:%02d:%02d\n",hour,minute,second); // 学瞎printf
}
return 0;
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)