[蓝桥杯][2018年第九届真题]航班时间

假设两地时间差为\(d\),飞机飞机时间为\(flytime\)

则去的实际花费时间为\(flytime=arrivetime_1 - starttime_1+d\),回来的实际花费时间为\(flytime=arrivetime_2-starttime_2-d\)

\(flytime = \frac{(arrivetime_1 - starttime_1) + (arrivetime_2-starttime_2)}{2}\)

const int N=1e5+10;
struct Node
{
    int hh,mm,ss,d;
    Node()
    {
        hh=mm=ss=d=0;
    }
    int calc()
    {
        return hh*3600+mm*60+ss+d*24*3600;
    }
};
int n;

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        Node a,b;
        scanf("%d:%d:%d",&a.hh,&a.mm,&a.ss);
        scanf("%d:%d:%d (+%d)",&b.hh,&b.mm,&b.ss,&b.d);
        int cometime=b.calc()-a.calc();
        
        Node c,d;
        scanf("%d:%d:%d",&c.hh,&c.mm,&c.ss);
        scanf("%d:%d:%d (+%d)",&d.hh,&d.mm,&d.ss,&d.d);
        int backtime=d.calc()-c.calc();


        int res=(backtime+cometime)/2;
        printf("%02d:%02d:%02d\n",res/3600,res%3600/60,res%3600%60);
    }
    //system("pause");
    return 0;
}
posted @ 2021-03-27 21:11  Dazzling!  阅读(95)  评论(0编辑  收藏  举报