60分江湖救急!!!

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

bestman_me @ 2023-09-02 20:22:27

#include<bits/stdc++.h>
using namespace std;
int main(){
    int sum = 10;
    int s,v,n,m;
    cin>>s>>v;
    n = s/v;
    if(s-n*v!=0) n++;
    sum+=n;
    if(sum<60){
        cout<<"07:";
        if(60-sum<10) cout<<"0"<<60-sum<<endl;
        else cout<<60-sum<<endl;    
    }
    else{
        m = sum/60;
        sum = sum-m*60;
        if(m>=8) cout<<8-m+23<<":";
        else cout<<"0"<<8-m<<":";
        if(60-sum<10) cout<<"0"<<60-sum<<endl;
        else cout<<60-sum<<endl;
    }
    return 0;
}

by GoodLuckCat @ 2023-09-02 20:39:20

@bestman_me

#include<bits/stdc++.h>
using namespace std;
int main(){
    int sum = 10;
    int s,v,n,m;
    cin>>s>>v;
    n = s/v;
    if(s-n*v!=0) n++;
    sum+=n;
    if(sum<60){
        cout<<"07:";
        if(60-sum<10) cout<<"0"<<60-sum<<endl;
        else cout<<60-sum<<endl;    
    }
    else{
        m = sum/60;
        sum = sum-m*60;
        if(m>=8) cout<<8-m+23<<":";
        else cout<<"0"<<7-m<<":";
        if(60-sum<10) cout<<"0"<<60-sum<<endl;
        else cout<<60-sum<<endl;
    }
    return 0;
}

应该是7-m,不是8-m


by bestman_me @ 2023-09-02 20:51:55

@Huyuhao0215

大佬,为啥输入“470 1”的结果为23:60?

有解决办法吗


by GoodLuckCat @ 2023-09-02 21:03:07

@bestman_me 我的代码是这样的

#include<cmath>
#include<iostream>
using namespace std;
int main()
{
    int s,v,h,m,a;
    cin>>s>>v;
    a=1910-ceil((double)s/(double)v);
    h=a/60;
    m=a%60;
    if(h>=24)h-=24;
    if(h<10)cout<<0;
    cout<<h<<":";
    if(m<10)cout<<0;
    cout<<m<<endl;
    return 0;
}

by GipsyAvenger1 @ 2023-09-03 15:52:56

#include <bits/stdc++.h>
using namespace std;
int s, v, wt, gt, gh, gm; 
int main(){
    cin >> s >> v;
    wt = s/v;
    if(s%v!=0)
        wt++;
    gt = (480 + 2880 - 10 - wt)%1440;
    gh = gt/60;
    if(gh<10)
        cout << 0;
    cout << gh << ':';
    gm = gt%60;
    if(gm<10)
        cout << 0;
    cout << gm << endl;
    return 0;
}

by bestman_me @ 2023-09-08 21:01:18

@Huyuhao0215 ceil是什么意思呀


|