求助,我这串代码运行起来没东西(c语言)

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

aoqichongtian @ 2023-11-20 19:42:53

#include <stdio.h>
int main() {
    int s, t;
    scanf("%d %d", &s, &t);
    int time = 0;
    time = s / t + 10;
    if (s % t != 0) {
        time++;

    }
    else {
        if (time < 480) {
            int h1 = 0;
            int m1 = 0;
            h1 = time / 60;
            m1 = time % 60;
            printf("02%d:%02d", 7 - h1, 60 - m1);

        }
        else {
            int h2 = 0;
            int m2 = 0;
            h2 = time / 60 - 8;
            m2 = time % 60;
            printf("02%d:02%d", 23 - h2, 60 - m2);
        }

    }
    return 0;

}

刚刚拖到编译器看了下,输入完s,v之后后面就不执行了,求大佬看看这是什么原因?


by N_ty @ 2023-11-20 20:03:46

样例 100 99 time=11; time++; 不是,你在else输出干嘛,如果if成立else就不成立啊


by N_ty @ 2023-11-20 20:04:12

@aoqichongtian


by N_ty @ 2023-11-20 20:04:49

#include<bits/stdc++.h>
using namespace std;
double s,v,m;
int n,a,t,b;
int main()
{
    cin>>s>>v;
    n=8*60+24*60;
    t=ceil(s/v)+10;
    n=n-t;
    if(n>=24*60) n=n-24*60;
    b=n%60;
    a=n/60;
    if(a<10)
    {
        if(b<10) cout<<"0"<<a<<":0"<<b;
        else cout<<"0"<<a<<":"<<b;
    }
    else
    {
        if(b<10) cout<<a<<":0"<<b;
        else cout<<a<<":"<<b;
    }
    return 0;
}

by N_ty @ 2023-11-20 20:07:48

给个关注


by aoqichongtian @ 2023-11-20 20:07:57

@yejingzhi emmm,写完if语句老是忍不住再写个else,问题解决了,谢谢大佬了!


|