8和10求助求助!qaq

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

dawndawnz @ 2024-10-15 18:40:18

#include<stdio.h>

int main(void)  
{  
    int late, hh, mm;  
    float s, v, t;  
    float school = 480.0;   
    scanf("%f%f", &s, &v);  
    t = s / v;  
    late = (int)(school - (10+t));  
    if (late < 0)  
        late += 24 * 60;  
    hh = late / 60;  
    mm = late % 60;  
    if (hh < 10)  
    {  
        if (mm < 10)  
            printf("0%d:0%d", hh, mm);  
        else  
            printf("0%d:%d", hh, mm);  
    }  
    else  
    {  
        if (mm < 10)  
            printf("%d:0%d", hh, mm);  
        else  
            printf("%d:%d", hh, mm);  
    }  

    return 0;  
}  

by wuxuanxuanxuan @ 2024-10-15 18:56:52

@dawndawnz

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

求关


by SunXiaolang @ 2024-10-15 18:57:08

你这个输出环节可以更简洁一些,把它限制只能输出两位,要不然用零补掉```c printf ("%02d:%02d",x/60,x%60);


by SunXiaolang @ 2024-10-15 18:57:43

#include<bits/stdc++.h>
using namespace std;

int main(){
    int s,v,x;
    double time;
    cin>>s>>v;
    time=ceil (s*1.0/v);
    x=480-time-10;
    if (x>0) {
        printf ("%02d:%02d",x/60,x%60);
    }
    else if (x==0){
        cout<<"00:00";
    }
    else{
        x=1440-(time-480)-10;
        printf ("%02d:%02d",x/60,x%60);
    }
}

by SunXiaolang @ 2024-10-15 18:58:19

@dawndawnz


by dawndawnz @ 2024-10-17 20:13:47

谢谢!


by dawndawnz @ 2024-10-17 20:14:08

谢谢!


|