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 2345A @ 2024-03-05 10:20:13

@zzh0118


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int s, v, x = 0, shijian = 0, xiaoshi = 0, fengzhong = 0;
    cin >> s >> v;
    x = ceil(1.0 * s / v) + 10;//要乘1.0
    shijian = 60 * 32 - x;
    xiaoshi = (shijian / 60) % 24;
    fengzhong = shijian % 60;
    if (xiaoshi < 10&&fengzhong>=10)
    {
        cout << "0" << xiaoshi << ":" << fengzhong;
    }
if(xiaoshi<10&&fengzhong<10)
  {
    cout<<"0"<<xiaoshi<<":0"<<fengzhong;
 }
 if(xiaoshi>=10&&fengzhong>=10)
 {
    cout<<xiaoshi<<":"<<fengzhong;
 }
 if(xiaoshi>=10&&fengzhong<10)
{
cout<<xiaoshi<<":0"<<fengzhong;
}
    return 0;
}

by 2345A @ 2024-03-05 10:21:42

@zzh0118 你的判断条件太多了


by 2345A @ 2024-03-05 10:35:23

@zzh0118 再用你的可能的思路写一个:


#include<bits/stdc++.h>
using namespace std;
int main(){
    int t,n,x,y;
    double s,v;//小数,小数!!!
    cin>>s>>v;
    t=ceil(s/v)+10;
    n=8*60+24*60-t;
    if(n>=24*60) n-=24*60;
    x=n/60;
    y=n%60;
    if(x>=10){//你一般用的优良马蜂
        if(y>=10) cout<<x<<":"<<y;
        else cout<<x<<":"<<"0"<<y;
    }
    else {
        if(y>=10) cout<<"0"<<x<<":"<<y;
        else cout<<"0"<<x<<":"<<"0"<<y;
    }
    return 0;
}

by 2345A @ 2024-03-05 10:48:49

@zzh0118 最后,你前面的代码没有问题,后面的代码判断的太多了,所以我修改了你的代码主要是你的马蜂我真看不懂


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

上一页 |