HS08TEST - Editorial

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??

import java.io.*;
class HS08TEST
{ public static void main(String args[])throws IOException
{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s=br.readLine();
int x=Integer.parseInt(s.substring(0,s.indexOf(’ ‘)));
double y=Double.parseDouble(s.substring(s.indexOf(’ ‘)+1));
if( y-x-0.5<x+0.5 || x%5!=0)
{ System.out.println(s.substring(s.indexOf(’ ‘)+1));
}
else
{ double result=y-x-0.50;
String st=result+“”;
if(Integer.parseInt(st.substring(st.indexOf(’.')+1))>9)
{ System.out.println(st);
}
else
{ System.out.println((st+“0”));
}
}
}
}

what is wrong with this code? it is working perfectly in BlueJ but showing WA in CodeChef compiler

import java.util.Scanner;
import java.io.*;

class Codechef1
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println(“Amount of cash you want to withdraw”);
int x = sc.nextInt();
if(0<x && x<=2000)
{
System.out.println(“Your intial account balance”);
double y = sc.nextDouble();
if(0<y && y<=2000)
{
if(x%5==0 && x<=y)
{
double rem = y-x-0.50;
System.out.println(“"+rem); } else { System.out.println("”+y);
}
}
}
}
}

WHAT’S Wrong with this code?

main()
{
int x;
double y=0.00,z=0.50;
cin>>x>>y;
while(x>0 && x<=2000 && y>=0 && y<=2000)
{
if(x%5==0 && x<y)
{
z= (y-x)-z;
cout<<setprecision(2)<<fixed<<z;
break;
}
else
cout<<setprecision(2)<<fixed<<y;
break;
}
return 0;
}

Why is this wrong?

#include<stdio.h>
int main()
{
int a,b,temp=0;
float c,d;
scanf("%d%f",&a,&c);
if(a%5==0 && a<=2000 && c<=2000.00)
{
b=1;
if(a<c)
{
temp=1;
}

}
else
{
	b=0;
}
if(b==1 && temp==1)
{
	printf("\n Successful Transaction");
	c=c-0.50;
	c=c-a;
	printf("\n Available Balance is %0.2f",c);
}
else if(b==0)
{
		printf("\n Invalid transaction or check your balance, Please enter amnount in multiple of 5");
			printf("\n Available Balance is %0.2f",c);
}
else
{
	printf("\n Insuficient fund");
	printf("\n Available Balance is %0.2f",c);

}

}

whats wrong in this program

#include
#include<stdio.h>
#include
using namespace std;
int main()
{
int x;
float y;
cin>>x;
cout<<"\t";
cin>>y;
if(x%5==0 && y-(x+0.5)>0)
{
cout<<"\n";
cout<<setprecision(2)<<y-(x+0.5)
}
else
{
cout<<"\n";
cout<<setprecison(2)<<y;

}
return 0;
}#include
#include<stdio.h>
#include
using namespace std;
int main()
{
int x;
float y;
cin>>x;
cout<<" “;
cin>>y;
if(x%5==0 && y-(x+0.5)>0)
{
cout<<”\n"<<setprecision(4)<<y-(x+0.5);
}
else
{
cout<<"\n"<<setprecision(4)<<y;
}
return 0;
}

Can someone tell me why my code worked with printf and not cout and setprecision??

X = int(input())
Y = float(input())

if X>0 and X<=2000 and Y>=0 and Y<=2000:
    if X<=Y and X%5==0:
        Y = float(Y - X - 0.50)
        print("%.2f" % Y)
    else:
        print("%.2f" % Y)

I say Runtime error but why?

@noswear

input contains only one line,but you are taking 2 lines of input and hence you are getting runtime error.Take single line of input and split them.Then your code will work fine.