HS08TEST - Editorial

#include
using namespace std;
int main()
{
int n,ch;
cin>>n>>ch;
float sum=0;
if((n+0.5<=ch)&&(n%5==0))
{
sum=ch-(n+0.5);
cout<<sum<<"\n";
}
else
{
sum=ch;
cout<<sum<<"\n";
}
return 0;
}
What is wrong with mine code, codechef Judge is giving it wronf Answer??? PLease Help

#include <stdio.h>
void main()
{
int x;
float y;
scanf("%d %f",&x,&y);
if(x%5==0 && y>(x+0.5))
printf("%0.2f\n",((y-(x+0.50))));
else
printf("%0.2f\n",y);
}

import java.util.Scanner;
class Main{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
int X;
double Y;

		X=input.nextInt();
if (X<=0||X>2000)
{		 input.close();
return;
}

		Y=input.nextDouble();
if (Y<0||Y>2000)
{
		 input.close();
return;
}
if(X%5==0)
	Y=Y-X-0.50;
System.out.println(Y);
 input.close();
return;

}
}

#include<stdio.h>
int main()
{
float bal;
int withdrawl;
scanf("%d",&withdrawl);
scanf("%f",&bal);
if(withdrawl>0&&withdrawl<=2000)
{
if(bal>=0&&bal<=2000)
{
if(withdrawl<bal)
{
if(withdrawl%5 == 0)
{
bal = bal-(withdrawl+0.50);
}
}
}
}
printf("%0.2f",bal);
return 0;
}

this code is working properly in online compiler of codechef .
but its not being accepted in the submit section.

#include<stdio.h>

int main()
{
   int X;
   float Y;
   scanf("%d %f",&X,&Y);
   if(Y<2000)
   if((X%5==0)&&(X<Y))
    Y=Y-X-.5;
   printf("%.2f",Y);
   
   return 0;
} 

it gets all test cases but shows ‘Wrong answer’

#include<stdio.h>
int main()
{
int x;
float y , z;
scanf("%d",&x);
scanf("%f",&y);
if(y>=0 && y<=2000);
{
if(x!=0 && x%5==0 && x<y)
printf("%f",y-x-0.50);
}
if(x%5!=0 || x>y )
printf("%f",y);
if(x==0 || x==y)
printf("%f",y);
return 0;
}
what is wrong with the code any one can run it on code blocks and can check it
i have to copy other’s code to proceed further

1 Like

#include
using namespace std;
int main()
{
int a;
float b;
cin>>a,b;
if(((a+0.50)<b) && (a%5==0))
{
cout<<(b-a-0.50);
}else {
cout<<b;
}

return 0;

}

//what is wrong in this? please tell.

import java.io.;
import java.util.
;
class joss_
{
public static void main(String args[]){
int c,i,t;
int s=0;
int e,h=0;
double f,g;
Scanner sc=new Scanner(System.in);
System.out.println(“”);
e=sc.nextInt();
f=sc.nextDouble();
g=f-e-0.5;
if((g<0)||((f%5)!=0)||(e>2000)||(f>2000))
{
g=f;
}
System.out.println(g);
}
}

What is wrong…?

Are you sure that your output is upto 2nd decimal place @anany_097?

because 120.000 is NOT 120.00 and hence would be flagged wrong.
Also, e is the money to be withdrawn. make sure that e is a multiple of 5.

Can anyone tell me that why the Codechef mark it as a wrong answer?

    #include <stdio.h>
 
    int main(void) {
	int x; //amount to withdraw
	float y; 	//initial balance
	
	scanf("%d %f",&x,&y);
	if((x>0) && (x<=2000) && (y>=0) && (y<=2000))
	{
		if((x<y) && (x%5 ) == 0)
			printf("%.2f",y-x-0.50);
		else
			printf("%.2f",y);
	}
	
	return 0;
}

withdraw**+0.50**>bankamount
This condition is necessary when in input is :
120 120.00
output should be :
120.00
not :
-0.50

3 Likes

#include <stdio.h>

int main(void)

{
int x=0;

float y=0;

scanf("%d",&x);

scanf("%f", &y);

if((x%5==0)&&(x<y))

{
    y = y - x - 0.50;

   printf("%.2f", y);

}

else

printf("%.2f", y);

return 0;

}

how is this a wrong answer?

#include
#include
using namespace std;

int main()
{
int x;
float output,y;
std::cin >> x >> y;
if((x>2000 || x <=0) || (y > 2000 || y < 0))
{
return 0;
}
if(x>y)
{
std::cout << fixed <<std::setprecision(2) << y;
}
else
if(x % 5 != 0)
{
std::cout << fixed << std::setprecision(2) << y;
}
else
{
output = y - x - 0.50;
std::cout << fixed << std::setprecision(2) << output;
}
return 0;
}

WHAT IS WRONG IN THIS CODE???

#include<stdio.h>
main()
{
int x,y,p;float z;
printf(“enter the initial account balance”);scanf("%d",&y);printf(“enter the amount you want to withdraw”);scanf("%d",&x);
p=x%5;
if((0<=x<=2000)&&(0<=y<=2000)&&(x<y)&&(p==0))
{z=y-x-0.5;printf(“the current account balance is %.2f”,z);}
else
printf(""%.2f",(float)y);
}

#include<stdio.h>
main()
{
int x,y,p;float z;
printf(“enter the initial account balance”);scanf("%d",&y);printf(“enter the amount you want to withdraw”);scanf("%d",&x);
p=x%5;
if((0<=x<=2000)&&(0<=y<=2000)&&(x<y)&&(p==0))
{z=y-x-0.5;printf(“the current account balance is %.2f”,z);}
else
printf(""%.2f",(float)y);
}

include

using namespace std;

int main() {

// your code goes here

double bal;

int wid;

cin>>wid;

cin>>bal;

cout.precision(2);

cout.setf(ios::showpoint);

if(wid%5!=0||wid>bal-0.50)

    cout<<fixed<<bal;

else

    {

        cout<<fixed<<bal-wid-0.50;

    }

return 0;

}

1 Like

package main

import (
“strconv”
“fmt”
“math”
)
func main(){

fmt.Print("Enter Amount : ")

var amount string

fmt.Scanln(&amount)

var ar float64

i, _ := strconv.ParseFloat(amount,64)

h := math.Mod(i, 5.0)

if i <= 2000{

if h != 0 {

fmt.Print(ar)

}

if h == 0{

var va float64

va = ar - i - 0.50

fmt.Print(“Balance :”)

fmt.Print(va)
}
}

if i > 2000 {

fmt.Print(ar)

}

}

I wrote this code in go ,it works fine in my laptop ,but not in codechef. Is there any problem with it?

Don’t print any statements,printing only answer is enough

import java.util.Scanner;

class Atm{

public static void main(String[] args){

	Scanner s=new Scanner(System.in);
	System.out.println("enter amt to be withdrawn:");
	double a=s.nextDouble();
	System.out.println("enter the current amout in account");
	double b=s.nextDouble();
	if((0<a)&&(0<b)){
		if((a<=2000.0)&&(b<=2000.0)){
			if(a>b) System.out.println(b);
			if((a%5)!=0) System.out.println(b);
			if(((a%5)==0)&&(a==b)) System.out.println(b-a);
			if(((a%5)==0)&&(a<b)) System.out.println((b-a)-0.50);
		}
	}
}

}

whats wrong with this code?

2 Likes

#include<stdio.h>
int main()
{
float y;
int x;
scanf("%d",&x);
scanf("%f",&y);
if(x>0&&x<=2000&&y>=0&&y<=2000)
{
if(x>=y)
printf("%.2f",y);
else if(x%5!=0)
printf("%.2f",y);
else
printf("%.2f",y-x-0.5);
}
return 0;
}

what’s wrong with this??