求助
查看原帖
求助
1056927
caibi666楼主2023/8/18 17:01

在洛谷的《深入浅出》中的答案,原本是c语言,我参考思路,改编成c++,但在VS上编译成功,提交时却显示编译失败。如果解决问题,这个代码绝对比题解还精简。 下面是书中的代码

#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
    int s, v;
    scanf("%d%d", &s, &v);
    int t_walk = ceil(1.0 * s / v) + 10;
    int from_zero = 60 * (24 + 8) - t_walk;
    int hh = (from_zero / 60) % 24;
    int mm = from_zero % 60;
    printf("%02d:%02d\n", hh, mm);
    return 0;
}

这是我改的代码

#include <iostream>
using namespace std;
int main()
{
    int s, v, HH, MM;
    cin >> s >> v;
    HH = (32 * 60 - s / v - 10) / 60 % 24;
    MM = (32 * 60 - s / v - 11) % 60;
    printf("%02d:%02d", HH, MM);
    return 0;
}

这是显示的结果: /tmp/compiler_ebmiicwr/src: 在函数‘int main()’中: /tmp/compiler_ebmiicwr/src:9:6: 错误:‘printf’在此作用域中尚未声明 9 | printf ("%02d:%02d" , HH , MM ); | ^~~~~~ /tmp/compiler_ebmiicwr/src:2:1: 附注:‘printf’ is defined in header ‘’; did you forget to ‘#include ’? 1 | #include +++ |+#include 2 | using namespace std;

2023/8/18 17:01
加载中...