30分求助,是算法太繁琐还是哪里出了错

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

cocogogo @ 2023-11-02 19:21:17

#include <stdio.h>
int main(){
    int s,v,hour,h2,min1,min2,time;
    scanf("%d%d",&s,&v);
    if(s%v==0) time=s/v+10;
    else time=s/v+11;
    if(time<=480){
        if(time%60==0) hour=time/60;
        else hour=time/60+1;
        min1=time%60;
        min2=60-min1;
        h2=8-hour;
        }
        else{
        if(time%60==0) hour=time/60;
        else hour=time/60+1;
        min1=time%60;
        min2=60-min1;
        h2=32-hour; 
        }
    if(min2<10) printf("%2d:0%d",h2,min2);
    else 
    printf("%2d:%2d",h2,min2);
    return 0;
}

by DESCENDANTSOFDRAGON @ 2023-11-02 19:45:54

#include<stdio.h>
using namespace std;

int main(){
    int h,m,x,y,s,v,i; 
    scanf("%d%d",&s,&v);

    if(s%v==0) i=10+s/v; 
    else i=11+s/v;

    if(480-i<0){  
        x=1440+(480-i);  
        h=x/60;       
        m=x%60;      
    }
    else{     
        y=480-i;
        h=y/60;
        m=y%60;
    }

    if(h>=10){    
        if(m>=10) printf("%d:%d",h,m);
        else printf("%d:0%d",h,m);
    }
    else{
        if(m>=10)  printf("0%d:%d",h,m);
        else printf("0%d:0%d",h,m);
    }
    return 0;
}

可以参考一下,求关注qwq


by Im_Joker @ 2023-11-06 22:31:14

@cocogogo 参考一下?

#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int h,m=1920,s,u;
    scanf("%d %d",&s,&u);
    if(s%u==0){
        m-=s/u;
    }else{
        m-=s/u;
        m--;
    }
    m-=10;
    if(m>=1440){
        m-=1440;
    }
    h=m/60;
    m%=60;
    printf("%02d:%02d",h,m);
    return 0;
}

|