gpt4 book ai didi

c++ - 没有给出测试用例时如何输入?

转载 作者:行者123 更新时间:2023-11-28 01:54:06 25 4
gpt4 key购买 nike

我在 SPOJ 上解决了这个问题。

http://www.spoj.com/problems/NECSTASY/

Problem Image

这是我的代码。

#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>

const float PI=3.14159265;

using namespace std;

int main()
{
float d,x,y,t;
while((cin >> d >> x >> y >>t)!=EOF)
{
float u= PI*(t/180);
float l = (d-y);
float k = l*(1/sin(u/2));
float h = k+x;
cout << fixed << setprecision(2) << h << endl;
}
return 0;
}

我面临一个问题,因为没有给出任何测试用例。

我该如何处理?

最佳答案

只需将 while((cin >> d >> x >> y >>t)!=EOF) 替换为 while(cin >> d >> x >> y >>t).

cin 在读取失败时将计算为 false。

更多详情请阅读:std::basic_ios::operator bool

Returns true if the stream has no errors and is ready for I/O operations. Specifically, returns !fail().

EOF另一方面是 int 类型和负值(宏常量)的整数常量表达式,不会等于 false

关于c++ - 没有给出测试用例时如何输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41847003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com