求助!70分!

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

ClashCalling @ 2024-02-16 14:43:03

#include <bits/stdc++.h>
using namespace std;
int main(){
    int s,v;
    int h=7;
    cin >> s >> v;
    int ti = (s/v);
    if(s%v!=0){
        ti++;
    }

    int k = 60 - ti - 10;
    if(k<0){
        while(k<0){
            k+=60;
            h--;
        }
    }
    if(h<0){
        h+=24;
    }
    cout << 0 << h << ":";
    if(k<10){
        cout << 0 << k;
    }else{
        cout << k;
    }
    return 0;
}

by Tsuki091117 @ 2024-02-21 20:40:02

@cyzyyds122 h有可能>10

#include <bits/stdc++.h>
using namespace std;
int main(){
    int s,v;
    int h=7;
    cin >> s >> v;
    int ti = (s/v);
    if(s%v!=0){
        ti++;
    }
    int k = 60 - ti - 10;
    while(k<0){
        k+=60;
        h--;
    }
    if(h<0){
        h+=24;
    }
    if(h<10){
        cout << 0;
    }
    cout << h << ":";
    if(k<10){
        cout << 0 << k;
    }else{
        cout << k;
    }
    return 0;
}

|