TRENDING NEWS

POPULAR NEWS

Why Am I Getting The Wrong Answer

SPOJ is a online coding platform. You have to take input as STDIN and output as STDOUT. And you need to be more specific about the way the output is required. You can't be fancy in that. Your way of displaying answer is wrong and don't print/ display un-required   items

Remove these 2 lines :-  if(sum>=something)continue;and enjoy AC :)

Why is my TI-83 Plus getting the wrong answer?

I was following through an example in my math book with my TI-83 Plus calculator, and I noticed I was getting a wrong answer to this equation:
Matrices:
A=
[[ 1 1 1 1]
[ 8 4 2 1]
[27 9 3 1]
[64 16 4 1]]
B=
[[ 1]
[ 4]
[10]
[20]]

Equation:
A^-1 * B

The book says and doing it out on paper confirms the answer should be:
[[1/6]
[1/2]
[1/3]
[ 0]]
And the calculator gives the same answer for all but the bottom one, where it gives -1.8E-12 instead of 0.

Why isn't the calculator also getting zero?

The answer is beyond the limit of integers or even unsigned long long int for that matter.

Why am i getting the wrong answers? how to properly plug in a graphing calculator?

you're in radian mode! swap to degree mode. what calculator do you've? Press mode next to the second one button. Scroll down 2 circumstances and examine degree mode particularly of radians.

A very good tool developed by Spoj Guys to get the output of any valid input to the problem. http://www.spojtoolkit.com/test/NTICKETS . This is the link to get the output for Problem Code "NTICKETS". It work as follows : "http : // www . spojtoolkit . com / test / PROBLEMCODE". A very useful tool to get the output rather than computing yourself. It somehow reduces some effort to de-bug the code. may be not like Codeforces or top coder.

Spoj Submissions are private so I cannot access your code.SIGFPE( Signal: Floating point exception) may occur due todivision by zeromodulo operation by zerointeger overflow (when the value you are trying to store exceeds the range) - trying using a bigger data type like long long.Edit: After code has been made available.This is your code. I have commented corrections at appropriate places.int a,b,c;
while(1)
{
cin>>a>>b>>c;
if(a==0&&b==0&&c==0)
{
break;
}
else
{
int d=b-a;
int e=c-b;

if(e==d)
{
cout<<"AP "< }
double d1=b/a; // Here a can be zero
double e2=c/b; // Here b can be zero

// since a and b can be zero, they will cause SIGFPE.

if(e2==d1)
{
cout<<"GP "< }
}
}
return 0;
Since the problem was about SIGFPE, I have corrected that part only.The code is still incorrect and I think you have not the problem statement carefully. Please Re-read the problem statement( you have missed something important).

The question which you are solving on SPOJ has many testcases on which your code is run and tested.You might be getting correct answer for sure on Code Blocks for some of the test cases you input but they have a bunch of testcases which you need to pass in order to get an AC on that question.It'll be easy for someone to answer if you provide your code and the problem statement.Best of luck !!

You probably expected name to be capable of holding text, but you declared it as a number (specifically an integer). Actually, I know something else about you as well: You are compiling this program under Microsoft's Visual C++ compiler, and you ran in debug mode. Are you wondering how I know that?It's because of the value of name: -858993460. That's a very specific value: In hexadecimal, it's equal to 0xCCCCCCCC. This is a magic value that is used to mark a variable that has never been initialized (at least, it is in Visual C++ in debug mode!).So I know that name was never initialized, and that's true--it was never initialized. You may think you initialized it when you wrote cin >> name, but you didn't, because you didn't type in a number. When you chose to type in some text instead, cin returned an error code (in other words, the expression "cin >> name" returned false, and cin.fail() would return true because it failed to read a number). This error code occurred because it detected invalid input.The thing you actually want to happen is for name to be able to hold text. To do that, declare string name; instead of int name;. You will also need to add #include somewhere. Don't use a fixed size character array (i.e. char name[50];), because cin >> name; allows the user to type more than 50 characters, and this will be a security issue (i.e. your program can be used to hack into the system if a hacker is allowed to type their "name"). Don't learn bad habits like this; just use a string.

Thanks for A2A. I really cannot be of much help because this contest is ongoing and this is against thee Code Chef code of conduct. Now figuring out the algorithmic part is up to you but most of the times there is a bug in the coding part instead of the logic building. So for that i would suggest the following :-Dry run your code on a few easy test cases that you have prepared. Run your code on paper first.Do keep a check on boundary values. The extreme values as mentioned in the constraints are the ones that cause the bug sometimes. If possible, do test your code on these values.Code up a random test case generator for the problem and execute your code on those test cases.Lastly if nothing works out, then re-read your own code multiple times (NO EXECUTION this time). I am sure that you might find some silly mistake here and there in your code that does not show up during execution. I will be more than happy to check out your code, but after the contest is over. Happy Coding !!!!!!!!!!

TRENDING NEWS