求组 一直是90%

P5707 【深基2.例12】上学迟到

BDCYI @ 2024-09-18 16:20:50

#include <iostream>

int main()
{
    int s, v, t;
    std::cin >> s >> v;
    if (s / v == 0)
        t = s / v + 10;
    else
        t = s / v + 1 + 10;
    int t_h, t_m;
    if (t >= 60)
    {
        t_h = t / 60;
        t_m = t - t_h * 60;
    }
    else
    {
        t_h = 0;
        t_m = t;
    }

    if (t_h < 7)
    {
        t_h = 8 - t_h - 1;
        t_m = 60 - t_m;
        if (t_m >= 10)
            std::cout << "0" << t_h << ":" << t_m;
        else
            std::cout << "0" << t_h << ":" << "0" << t_m;
        return 0;
    }
    else if (t_h == 7)
    {
        t_m = 60 - t_m;
        if (t_m >= 10)
            std::cout << "00" << ":" << t_m;
        else
            std::cout << "00" << ":" << "0" << t_m;
        return 0;
    }
    else
    {
        t_h = 24 + 8 - t_h - 1;
        t_m = 60 - t_m;
        if (t_h >= 10)
        {
            if (t_m >= 10)
                std::cout << t_h << ":" << t_m;
            else
                std::cout << t_h << ":" << "0" << t_m;
        }
        else
        {
            if (t_m >= 10)
                std::cout << "0" << t_h << ":" << t_m;
            else
                std::cout << "0" << t_h << ":" << "0" << t_m;
        }       
        return 0;
    }    
}

by CHEN08_94 @ 2024-09-18 16:32:56

@BDCYI 第7行应该是s%v==0

#include <iostream>

int main()
{
    int s, v, t;
    std::cin >> s >> v;
    if (s % v == 0)
        t = s / v + 10;
    else
        t = s / v + 1 + 10;
    int t_h, t_m;
    if (t >= 60)
    {
        t_h = t / 60;
        t_m = t - t_h * 60;
    }
    else
    {
        t_h = 0;
        t_m = t;
    }

    if (t_h < 7)
    {
        t_h = 8 - t_h - 1;
        t_m = 60 - t_m;
        if (t_m >= 10)
            std::cout << "0" << t_h << ":" << t_m;
        else
            std::cout << "0" << t_h << ":" << "0" << t_m;
        return 0;
    }
    else if (t_h == 7)
    {
        t_m = 60 - t_m;
        if (t_m >= 10)
            std::cout << "00" << ":" << t_m;
        else
            std::cout << "00" << ":" << "0" << t_m;
        return 0;
    }
    else
    {
        t_h = 24 + 8 - t_h - 1;
        t_m = 60 - t_m;
        if (t_h >= 10)
        {
            if (t_m >= 10)
                std::cout << t_h << ":" << t_m;
            else
                std::cout << t_h << ":" << "0" << t_m;
        }
        else
        {
            if (t_m >= 10)
                std::cout << "0" << t_h << ":" << t_m;
            else
                std::cout << "0" << t_h << ":" << "0" << t_m;
        }       
        return 0;
    }    
}

by BDCYI @ 2024-09-18 16:41:41

十分感谢


|