卡在70分了,怎么搞都一样

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

zhouyang111 @ 2023-11-18 21:24:12

#include<bits/stdc++.h>

using namespace std;

int s,v,m,h;

int main(){ 

    cin>> s >> v;
    if(s % v == 0){
        m = s / v + 10;
    }else{
        m = s / v + 11;
    }
    h = m / 60 + 1;
    m = m % 60;
    if(h >= 8){
        h = (h-8)%24;
        printf("%02d:%02d",h,60-m); 
        return 0;
    }
    printf("%02d:%02d",8-h,60-m); 
    return 0;
} 

by ljcnoi @ 2023-11-19 17:13:23

建议讨论好各种情况,认真审题!

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int m=10;
    int s,v;
    cin>>s>>v;
    double sv=ceil(s*1.0/v);
    m=m+sv;
    int h=m/60;
    m=m%60;
    int tim=0,tih=8;
    tim=tim-m;
    if(tim<0)
    {
        tim=tim+60;
        tih--;
    }
    tih=tih-h;
    if(tih<0)
    {
        tih=tih+24;
    }
    if(tih<10)
    {
        cout<<0<<tih;
    }
    else
    {
        cout<<tih;
    }
    cout<<":";
    if(tim<10)
    {
        cout<<0<<tim;
    }
    else
    {
        cout<<tim;
    }
    return 0;
}

by ljcnoi @ 2023-11-19 17:17:41

@ljcnoi 实在不行就多写几个分支语句,虽然可能更加麻烦,但是没那么容易错。


|