小白求教

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

520dream330 @ 2024-10-09 17:27:35

我的代码如下

#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int t,h=0,p;
    double s,v,m=0,t1;
    cin >>s>>v;
    t=s/v;
    t1=s/v;
    if(t>=60){
        h=t/60;
        m=t%60;
    }else   m=t1;
    p=7-h;
    if(p>0) cout<<0;
    if(p<0){
        if(p>-21){
            p+=24;
        }else{
            cout <<0;
            p+=24;
        }
    }
    cout <<p<<":"<<50-ceil(m);
    return 0;
}

已经检查过很多遍了,给的测试数据也没问题,但提交后就是有报错,希望有大佬可以指点一下


by wuyusheng @ 2024-10-09 17:33:21

是报错还是WA?


by 520dream330 @ 2024-10-09 17:42:35

@wuyusheng wa,3,4,5,6,7,8,10,报错


by Chang__An__Li @ 2024-10-09 17:46:10

@520dream330

#include<bits/stdc++.h>
using namespace std;
int s,v;
int main(){
    scanf("%d%d",&s,&v);
    int t=10+ceil(s*1.0/v);
    int ans=8*60;
    ans-=t;
    if(ans<0){
        ans=ans+24*60;
    }
    if(ans/60<10)printf("0");
    printf("%d:",ans/60);
    if(ans%60<10)printf("0");
    printf("%d",ans%60);
    return 0;
}

这是满分代码


by Chang__An__Li @ 2024-10-09 17:50:42

@520dream330

看不懂p>0时为什么要输出前导0


by 520dream330 @ 2024-10-11 17:40:54

@ChangAnLi 大于0就代表时间的小时是单数(一定小于7),所以要个啊


|