30分求助

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

hez2022 @ 2023-09-22 21:21:54



#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,min=60,h=8,s=0,x=0;
    cin>>n>>m;
    s=n/m;
    if(n%m>0){
        s++;
    }
    if(s/60>0){
        h=h-s/60-1;
        s=s-(s/60)*60;
        min=min-s-10;
    }
    else{
        h=h-1;
        min=min-s-10;
    }
    if(min<0){
        h=h-1;
        x=min;
        min=min+x;
    }
    cout<<"0"<<h<<":"<<min;
    return 0;
}

by HASPID @ 2023-09-22 21:54:15

#include<iostream>
using namespace std;
int main(){
    int s,v,h=8,m,t;
    cin>>s>>v;
    if(s%v==0)t=s/v;
    else if(s%v!=0)t=s/v+1;
      t+=10;
    if(t%60==0)h=h-t/60;
    else h=h-t/60-1;
    if(h<0)h=24+h;
    if(t%60==0)m=0;
    else m=60-t%60;
    if(h<10&&m<10)cout<<0<<h<<":"<<0<<m;
    else if(h>=10&&m<10)cout<<h<<":"<<0<<m;
    else if(h<10&&m>=10)cout<<0<<h<<":"<<m;
    else if(h>=10&&m>=10)cout<<h<<":"<<m;
}

AC代碼


by HASPID @ 2023-09-22 21:55:07

有沒可能,h會等於負數


by HASPID @ 2023-09-22 21:55:39

@IMPOSTORrrrrrr MIN有可能個位數


|