如何编写代码实现航班时间效果

2023-05-12

这篇文章主要介绍“如何编写代码实现航班时间效果”,在日常操作中,相信很多人在如何编写代码实现航班时间效果问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”如何编写代码实现航班时间效果”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

string line;
getline(cin,line);

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>

using namespace std;

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 h2,m1,s1,h3,m2,s2,d;
    sscanf(line.c_str(),"%d:%d:%d %d:%d:%d (+%d)",&h2,&m1,&s1,&h3,&m2,&s2,&d);
    return get_seconds(h3,m2,s2) - get_seconds(h2,m1,s1) + d*24*3600;
}

int main(){
    int n;
    cin>>n;
    string line;
    //忽略掉第一行的回车
    getline(cin,line);
    while(n--){
        int time=(get_time()+get_time())/2;
        printf("%02d:%02d:%02d\n",time/3600,time%3600/60,time%60);
    }
    return 0;
}

到此,关于“如何编写代码实现航班时间效果”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注本站网站,小编会继续努力为大家带来更多实用的文章!

《如何编写代码实现航班时间效果.doc》

下载本文的Word格式文档,以方便收藏与打印。