[c]为什么#9过不了?求求大佬帮忙!

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

peana @ 2024-05-20 16:55:53

#include<stdio.h>
#include<math.h>
#define ot 8*60
#define gc 10
int main()
{
    int s,v;
    double t,t1;
    scanf("%d %d",&s,&v);
    t=s/v+gc;
    t1=ot-t;
    while(t1<0)
    {
        t1+=24*60;
    }
    int hour=(int)floor(t1/60);
    int min=(int)t1%60-1;
    printf("%02d:%02d",hour,min);
    return 0;
}

by glass_goldfish @ 2024-05-20 18:07:41

@peana AC代码来了。求加:https://www.luogu.com.cn/team/79073

#include<bits/stdc++.h>
using namespace std;
int s,v,sd,hh=7,mm=60;
int main()
{
    cin>>s>>v;
    if(s%v==0)sd=s/v;
    else sd=s/v+1;
    sd+=10;
    int h=sd/60;
    int m=sd%60;
    if(h>hh)hh+=24;
    int h1=hh-h;
    int m1=mm-m;
    if(m1==60){
        m1=0;
        h1++;
    }
    if(h1==24)h1=0;
    if(h1==0){
        cout<<"00:";
        if(m1==0)cout<<"00";
        else if(m1<10)cout<<"0"<<m1;
        else cout<<m1;
    }
    else if(h1<10){
        cout<<"0"<<h1<<":";
        if(m1==0)cout<<"00";
        else if(m1<10)cout<<"0"<<m1;
        else cout<<m1;
    }
    else{
        cout<<h1<<":";
        if(m1==0)cout<<"00";
        else if(m1<10)cout<<"0"<<m1;
        else cout<<m1;
    }
    return 0;
}

by peana @ 2024-05-21 16:15:31

#include<stdio.h>
#include<math.h>
#define ot 8*60
#define gc 10
int main()
{
    int s,v,t,t1,t2,hour,min;
    scanf("%d %d",&s,&v);
    t=s/v;
    if(s%v==0)
    {t2=t+gc;}
    else
    {t2=t+gc+1;}
    t1=ot-t2;
    while(t1<0)
    {
        t1+=24*60;
    }
    hour=t1/60;
    min=t1%60;
    printf("%02d:%02d\n",hour,min);
    return 0;
}

终于想出来了


|