1 / 6
Sep 2019

SPOJ : HANGOVER
I am new to SPOJ and My Solution is Passing all test Cases According to me but in SPOJ compiler My Solution is Wrong.I want To Know What is the Problem With My Solution.

#include<iostream>
#include<cstdlib>
using namespace std;

int main()
{
float desired=1.00;
while(1)
{
cin>>desired;
if(desired!=0 and desired<=5.20 and desired>=0.01)
{
float sum=0;
int denominator=2;
float num=1;
int total=0;
while(sum<=desired)
{
num=1.00/denominator;
sum+=num;
total+=1;
++denominator;
}
cout<<total<<" card(s)"<<"\n";
}
else
exit(0);
}
return 0;
}

  • created

    Sep '19
  • last reply

    Oct '19
  • 5

    replies

  • 705

    views

  • 2

    users

  • 3

    links

When I run it with this input:

0.01
0.00

It produces no output.

It Produces Correct Output For 0.01 i.e 1 card(s) but as Per Question: HANGOVER it should terminate when it takes 0.00 as Input. So,it does the Same.So, i think the Code is Correct but since i am new to competitive coding maybe my method of taking input and output maybe Wrong.

I believe it’s this5.

There’s no need to check the input is between 0.01 and 5.20. That’s the author of the problem telling you the range of input, but you probably shouldn’t exit if it’s not in that range. Particularly when comparing floating-point numbers.