为什么一直90分,求解

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

Dogyyds @ 2024-09-08 12:53:41

#include <stdio.h>
int main()
{
    int s,v;
    int t,h,m;
    scanf("%d %d",&s,&v);
    t = 24 * 60 + 8 * 60 - (s+v-1)/v - 10;
    h = t / 60;
    m = t % 60;
    if (h>24)
    {
        h -= 24;
    }
    printf("%02d:%02d\n",h,m);
    return 0;
}

by Dogyyds @ 2024-09-08 12:57:12

一直是第#7测试点WA


by renzhanwen @ 2024-09-08 12:58:00

@Dogyyds


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

    }
    else
    {
        k-=480;
        if(k%60==0)
        {
            if(24-k/60<10)
                cout<<"0";
            cout<<24-k/60<<":00";
        }   
        else
        {
            if(23-k/60<10)
                cout<<"0";
            cout<<23-k/60<<":";
            if(60-k%60<10)
                cout<<"0";
            cout<<60-k%60;
        }   
    }
    return 0;
}

by xvjingxvan3 @ 2024-09-08 12:58:12

哪一题??


by Dogyyds @ 2024-09-08 13:04:56

@renzhanwen 我看不懂C++ 我看别人写的c语言代码也看不出来自己哪里错了QAQ


by Dogyyds @ 2024-09-08 13:05:25

@xvjingxvan3 5707


by fangkai123 @ 2024-09-08 13:06:38

#include<bits/stdc++.h>
using namespace std;
int  main()
{
    double s,v,t;
    cin>>s>>v;
    t=ceil(s/v)+10;
    int h=ceil(t/60);
    int m=(int)t%60;

    printf("%.02d:%.02d",(8-h+24)%24,(0-m+60)%60);
    return 0;
}

by tildusk @ 2024-09-08 19:51:19

@Dogyyds 本题没24点只有0点,把if里面改成h>=24就行了


by Dogyyds @ 2024-09-08 21:20:54

@tildusk 成功了谢谢谢谢谢谢大佬,我想了好久都没想到问题


|