2 条题解

  • 0
    @ 2024-4-2 0:01:20

    【2021年省赛B组】试题F: 时间显示

    题解

    简单模拟题,语法补零, 由于不用考虑毫秒,所以可以去掉毫秒的精度。由于不用考虑年月日,所以只保留最后一天的时间即可。值的注意的是1s=1000s1s=1000s, 时间复杂度为O(1)O(1)

    提交代码

    • scanf printf 版
    #include<bits/stdc++.h>
    
    void solve()
    {
        long long x; scanf("%lld", &x);
        x /= 1000;
        x %= 24 * 60 * 60;
        printf("%02lld:%02lld:%02lld", x / 3600, (x % 3600) / 60, (x % 3600) % 60);
    }
    
    int main() 
    {
        int t = 1;
        while (t--) solve();
        return 0;
    }
    
    • cin cout 版
    #include<bits/stdc++.h>
    
    void solve()
    {
    	long long x; std::cin >> x;
        x /= 1000;
        x %= 24 * 60 * 60;
    	int hh = x / 3600;
    	int mm = (x % 3600) / 60;
    	int ss =  (x % 3600) % 60;
        std::cout << std::setfill('0') << std::setw(2) << hh << ":" << std::setw(2) << mm << ":" << std::setw(2) << ss << "\n";
    }
    int main() 
    {
        int t = 1;
        while (t--) solve();
        return 0;
    }
    

    信息

    ID
    981
    时间
    1000ms
    内存
    256MiB
    难度
    5
    标签
    递交数
    24
    已通过
    11
    上传者