https://www.codechef.com/problems/HS08TEST
In C++....................
#include<bits/stdc++.h>
using namespace std;
int main()
{
int X;
float Y,z,n=0;
scanf("%d",&X);
scanf("%f",&Y);
n=X+0.5;
if(n>Y)
{
printf("%f\n",Y);
}
else
{
if(X%5==0)
{
z=Y-n;
printf("%.2f\n",z);
}
else
{
printf("%f\n",Y);
}
}
return 0;
}
In C++....................
#include<bits/stdc++.h>
using namespace std;
int main()
{
int X;
float Y,z,n=0;
scanf("%d",&X);
scanf("%f",&Y);
n=X+0.5;
if(n>Y)
{
printf("%f\n",Y);
}
else
{
if(X%5==0)
{
z=Y-n;
printf("%.2f\n",z);
}
else
{
printf("%f\n",Y);
}
}
return 0;
}
Why did you use n=X+0.5; here?
ReplyDelete