|  | 
|  | 
| back to board | Please help! Wrong answer (C++) My program works fine in console, but for some reason I get wrong answer on test 9. Could someone point out where is the problem in my code?
 #include <iostream>
 #include <vector>
 #include <math.h>
 #include <iomanip>
 
 using namespace std;
 
 int main()
 {
 double num;
 vector<long long> input;
 int limit  = 256 * 1024 / sizeof(long long);
 for (int k = 0; (cin >> num) && k <= limit; k++)
 {
 if (num != (long long)num || num < 0 || num > pow(10.0, 18))
 return 0;
 input.push_back((long long)num);
 }
 for (int i = input.size() - 1; i >= 0; i--)
 cout << fixed << setprecision(4) << sqrt(input[i]) << endl;
 
 return 0;
 }
 
 Edited by author 28.03.2016 23:17
 
 Edited by author 28.03.2016 23:18
 
 Edited by author 28.03.2016 23:18
Re: Please help! Wrong answer (C++) Limit is wrong. Min number size is 2 bytes - "1 ".
 In common, you shouldn't check if input is correct. It's supposed to be always correct.
 Reading like:
 while (cin >> number) {
 input.push_back(number);
 }
 should be enough.
 
 If you want to check input (for lulz?) you should fail your program in more visible way - via return not 0, throw something etc. Judge system will return another error, not WA.
 
 
 Edited by author 28.03.2016 23:43
Re: Please help! Wrong answer (C++) Another note.
 You read number into double, convert it into long long, convert it back to double and finally call sqrt.
 Why do you need 2 conversions in the middle?
 Shouldn't you better use vector<double> input?
Re: Please help! Wrong answer (C++) Sorry for stupid question: what is WA?Re: Please help! Wrong answer (C++) Posted by retired  29 Mar 2016 02:04"Wrong Answer"Re: Please help! Wrong answer (C++) | 
 | 
|