求助 70分

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

aaaaaxxx @ 2023-10-29 16:53:47


#include <iostream>
using namespace std;
int main()
{
    int s,v,t,a,b;
    cin>>s>>v;
    t=s/v+10;
    a=t/60;
    if(t % 60 ==0)
    b=60-t+a*60;
    else
        b=59-t+a*60;
    if(a<=8)
    {
        if(b>10)
        cout<<"0"<<7-a<<":"<<b<<endl;
        else
        {
            if(b==0)
        cout<<"0"<<8-a<<":"<<b<<endl;
            else
        cout<<"0"<<7-a<<":0"<<b<<endl;
        }

    }
    if(a>8)
    {
        if(b>10)
    cout<<32-a<<":"<<b<<endl;
        else
        {
            if(b==0)
            cout<<"0"<<32-a<<":0"<<b<<endl;
            else
            cout<<"0"<<31-a<<":0"<<b<<endl;

        }

    }
    return 0;

}
———————————————————————
最后三个没过。。。

by 1612855242ytq @ 2023-10-29 17:08:41

line 10 : b=0;

不然b就等于60了


by aaaaaxxx @ 2023-10-29 17:13:18

@1612855242ytq 好的佬,确实是个错误,但改完还是最后三个没过:C


by 1612855242ytq @ 2023-10-29 17:18:41

line 15&28 : 应该为b>=10

否则b=10的时候还是有前导零


by 1612855242ytq @ 2023-10-29 17:26:39

line 16&22 :可能会有7-8=-1吧


by 1612855242ytq @ 2023-10-29 17:28:13

遇到wa了几个点的情况,大部分是边界情况没有考虑充分,条件允许的情况下可以自己手写几个数据测试看看,特别是边界情况


by aaaaaxxx @ 2023-10-29 17:33:11

@1612855242ytq 好的佬,我去改改看,不会再来问。


|