Hi, I used to solve ACM problems, but I used old scanf & printf for input and output.But now i want to use C++ style IO. So, i picked a simple problem, and tried to convert its old style IO to new style IO.
The problem : http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=996
(in summery, as input two numbers will be given, and you have to print the difference of that two numbers. :P )
Old Style: Online Judge Accepts this code.
#include<stdio.h>
int main()
{
long double a,b,d;
while(scanf("%Lf %Lf", &a,&b) == 2){
if (a > b) d = a - b;
else d = b - a;
printf("%.Lf\n", d);
};
return 0;
}
New Code:
#include<iostream>
using namespace std;
int main()
{
long double a,b,d;
while(!cin.eof()){
cin >> a >> b;
if (a > b) d = a - b;
else d = b - a;
cout << d << endl;
cout.flush();
};
return 0;
}
But, New C++ code is not being accepted, judge keeps on saying wrong answer.
What am i doing wrong?