50分求助!(赏关一个)

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

zzh0118 @ 2024-03-04 20:28:40

代码如下:

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

求调


by wyxrl @ 2024-03-04 21:07:08

要加一个ceil向上取整虽然也是错的


by zzh0118 @ 2024-03-04 21:11:49

#include<bits/stdc++.h>
using namespace std;
int cnt=8*60+24*60,s,u,num,fen,shi;
int main(){
    cin>>s>>u;
    num=ceil(s/u)+10;//ceil的意思是向上取整,因为C++默认向下取整;
    cnt=cnt-num;
    if(cnt>=24*60){
        cnt-=24*60;
        shi=cnt/60;
        fen=cnt%60;
    }
    if(shi<10){
        if(fen%60==0){
            cout<<"0"<<shi<<":"<<fen;
        }
        else{
            cout<<"0"<<shi<<":"<<fen-1;
        }
    }
    else{
        if(fen%60==0){
            cout<<shi<<":"<<fen;
        }
        else{
            cout<<shi<<":"<<fen-1;
        }
    }
    return 0;
}

经过朋友指导变成了这样


by zzh0118 @ 2024-03-04 21:12:36

@wyxrl


by zzh0118 @ 2024-03-04 21:14:32

还是50分


by zzh0118 @ 2024-03-04 21:15:02

@lutaoquan2012


by lutaoquan2012 @ 2024-03-04 21:21:13

@zzh0118 来喽


by zzh0118 @ 2024-03-04 21:25:48

#include<bits/stdc++.h>
using namespace std;
int cnt=8*60+24*60,s,u,num,fen,shi;
int main(){
    cin>>s>>u;
    num=ceil(s/u)+10;//ceil的意思是向上取整,因为C++默认向下取整;
    cnt=cnt-num;
    if(cnt>=24*60){
        cnt-=24*60;
        shi=cnt/60;
        fen=cnt%60;
    }
    if(shi<10){
        if(fen<10){
            cout<<"0"<<shi<<":0"<<fen;
        }
        else{
            cout<<"0"<<shi<<":"<<fen;
        }
    }
    else{
        if(fen<10){
            cout<<shi<<":0"<<fen;
        }
        else{
            cout<<shi<<":"<<fen;
        }
    }
    return 0;
}

第三稿


by zzh0118 @ 2024-03-04 21:30:54

#include<bits/stdc++.h>
using namespace std;
int cnt=8*60+24*60,s,u,num,fen,shi;
int main(){
    cin>>s>>u;
    num=ceil(s/u)+10;//ceil的意思是向上取整,因为C++默认向下取整;
    cnt=cnt-num;
    if(cnt>=24*60){
        cnt-=24*60;
        shi=cnt/60;
        fen=cnt%60;
    }
    if(shi<10){
        if(fen<10){
            if(fen%60==0){
                cout<<"0"<<shi<<":0"<<fen;
            }
            else{
                cout<<"0"<<shi<<":0"<<fen-1;
            }
        }
        else{
            if(fen%60==0){
                cout<<"0"<<shi<<":"<<fen;
            }
            else{
                cout<<"0"<<shi<<":"<<fen-1;
            }
        }
    }
    else{
        if(fen<10){
            if(fen%60==0){
                cout<<shi<<":0"<<fen;
            }
            else{
                cout<<shi<<":0"<<fen-1;
            }
        }
        else{
            if(fen%60==0){
                cout<<shi<<":"<<fen;
            }
            else{
                cout<<shi<<":"<<fen-1;
            }
        }
    }
    return 0;
}

现在70了


by zzh0118 @ 2024-03-04 21:35:13

#include<bits/stdc++.h>
using namespace std;
int cnt=8*60+24*60,s,u,num,fen,shi;
int main(){
    cin>>s>>u;
    num=ceil(s/u)+10;//ceil的意思是向上取整,因为C++默认向下取整;
    cnt=cnt-num;
    if(cnt>=24*60){
        cnt-=24*60;
    }
    shi=cnt/60;
    fen=cnt%60;
    if(shi<10){
        if(fen<10){
            if(fen%60==0){
                cout<<"0"<<shi<<":0"<<fen;
            }
            else{
                cout<<"0"<<shi<<":0"<<fen-1;
            }
        }
        else{
            if(fen%60==0){
                cout<<"0"<<shi<<":"<<fen;
            }
            else{
                cout<<"0"<<shi<<":"<<fen-1;
            }
        }
    }
    else{
        if(fen<10){
            if(fen%60==0){
                cout<<shi<<":0"<<fen;
            }
            else{
                cout<<shi<<":0"<<fen-1;
            }
        }
        else{
            if(fen%60==0){
                cout<<shi<<":"<<fen;
            }
            else{
                cout<<shi<<":"<<fen-1;
            }
        }
    }
    return 0;
}

第四稿90分了


by 2345A @ 2024-03-05 10:18:40

@zzh0118 我来了


| 下一页