求助!20分

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

chenyifan12 @ 2024-09-18 20:48:10

代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{

    int timeh=7,timemin=50,s,v,times=0,timesy=0;;
    cin>>s>>v;
    timesy=s%v;
    times=(s-timesy)/v+1;
    while(times>=60){
        times-=60;
        timeh-1;
    }
    if(times>0){
        if(times>50){
            timeh-=1;
            times=60-times;
            timemin+=times;
        }
        else
        {
            timemin-=times;
        }
    }
    cout<<"0"<<timeh<<":"<<timemin;
    return 0;
}

by Florrer_A @ 2024-09-18 21:01:02

@chenyifan12 你这timeh=7不对,他不一定是在7点多出发


by Wangbingxiang @ 2024-09-18 21:07:40

#include<bits/stdc++.h>
using namespace std;
float s,v,t;
int main(){
    scanf("%f%f",&s,&v);
    t=ceil(s/v)+10;//需要总共提前多少分钟
    int h=ceil(t/60);//需要提前多少小时
    int m=(int)t%60;//要提前多少分钟
    printf("%02d:%02d",(8-h+24)%24,(0-m+60)%60);//输出
    return 0;
}

by Wangbingxiang @ 2024-09-18 21:11:51

timeh-1;不对 应为timeh-=1;

并且分钟输出是如果只有个位数,前面要补0 还有,他可能是在前一天晚上出发哟qwq


by chenyifan12 @ 2024-09-20 19:57:48

@Wangbingxiang 谢谢!经过修改,60分,还是没有满分

#include<bits/stdc++.h>
using namespace std;
int main()
{

    int timeh=7,timemin=50,s,v,times=0,timesy=0,i=0;
    cin>>s>>v;
    timesy=s%v;
    times=(s-timesy)/v+1;
    while(times>=60){
        times-=60;
        timeh-=1;
    }
    if(times>0){

        if(times>50){
            timeh-=1;
            times=60-times;
            timemin+=times;
        }
        else
        {
            timemin-=times;
        }
        if(timeh<0)
    {
        while(timeh<0){
            timeh++;
            i++;
        }
        timeh=24-i;
    cout<<timeh<<":"<<timemin+1;
    } 
    else
    cout<<"0"<<timeh<<":"<<timemin;
    }

    return 0; 
}

by chenyifan12 @ 2024-09-20 19:59:24

@Florrer_A 因为垃圾分类占10分钟!8:00 - 0:10 不是等于7:50吗?初始化为7,后面会减


by Wangbingxiang @ 2024-09-20 20:03:29

@chenyifan12 分钟前面有可能是0(如:07:07)


by chenyifan12 @ 2024-09-20 20:25:27

@Wangbingxiang 好谢谢


|