2017-01-25 12 views
0

私は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; 
} 

私は、テストケースが何も与えられていないという問題に直面しています。

どうすれば対処できますか?

+0

while((cin >> d >> x >> y >> t)!= EOF)。これはしないでしょうか? –

+1

いくつかのアドバイスについては、[この質問](http://stackoverflow.com/questions/201992/how-to-read-until-eof-from-cin-in-c)を参照してください。 – tadman

答えて

1

ちょうどwhile((cin >> d >> x >> y >>t)!=EOF)while(cin >> d >> x >> y >>t)に置き換えてください。

cinは、読み込みに失敗するとfalseに評価されます。

詳細についてお読みください:ストリームにエラーがないとI/O 操作のための準備ができているstd::basic_ios::operator bool

trueを返します。具体的には、!fail()を返します。一方

EOFは整数タイプintの定数式は負の値(マクロ定数)であり、falseに等しい来ないであろう。

1

テストコードを使用することができます。

#include <iostream> 
#include <iomanip> 
#include <cmath> 
#include <fstream> 
#include <stdio.h> 
const float PI=3.14159265; 
using namespace std; 
int main() 
{ 
float d,x,y,t; 
while(getchar()!=EOF) 
{ 
cin >> d >> x >> y >>t; 
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; 
} 
関連する問題