zoukankan      html  css  js  c++  java
  • 1231. 航班时间(字符串处理+sscanf用法)

    题目链接:

    https://www.acwing.com/problem/content/1233/

    题解:

    (飞行时间+时差 + 飞行时间 - 时差) / 2 = 飞行时间

    AC代码:

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    
    int getSecond(int h,int m,int s){
        return h*3600+m*60+s;
    }
    
    
    int getTime(){
        string t;
        getline(cin,t);
        if(t.back() != ')') t += " (+0)";
        int h1,m1,s1,h2,m2,s2,d;
        sscanf(t.c_str(),"%d:%d:%d %d:%d:%d (+%d)",&h1,&m1,&s1,&h2,&m2,&s2,&d);
        
        return getSecond(h2,m2,s2) - getSecond(h1,m1,s1) + d*24*3600;
    }
    
    
    int main(){
        int n;
        scanf("%d",&n);
        getchar();
        while(n--){
            
            int detTime = (getTime()+getTime())/2;
            int h = detTime / 3600;
            int m = detTime % 3600 / 60;
            int s = detTime % 60;
            
            printf("%02d:%02d:%02d
    ",h,m,s);
        }
        
        
        return 0;
    }
  • 相关阅读:
    map
    01背包和完全背包 POJ
    并查集 计算节点数量
    set
    map,vector,queue 图 综合运用
    并查集 hdu-1325 Is It A Tree?
    js中的ajax
    java算法
    MySql在Window上的安装
    微信开发账号要求
  • 原文地址:https://www.cnblogs.com/doubest/p/12305713.html
Copyright © 2011-2022 走看看