HS08TEST - Editorial

#include
#include <stdio.h>
using namespace std;

int main() {
// your code goes here
int x;
float y;
scanf("%d", &x);
scanf("%f", &y);
if(x>0 && x<=2000 && y>=0 && y<=2000 && x%5==0)
{
if(x>y)
{
printf("%0.2f", y);
}
else if(y>=x)
{
printf("%0.2f", (y-x-0.50));
}
}
else
{
printf("%0.2f", y);
}
return 0;
}

Can someone please tell me what is wrong with this episode?
Thank you in advance!!

have a look at your inner if where you’ve mentioned x>y
don’t forget about bank charges as well… so your condition should be

if(x % 5 == 0 && y >= x+0.5)

just this one if would work

/* package codechef; // don’t place package name! */

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int x =sc.nextInt();
double f = sc.nextDouble();

	if((0<=x && x <=2000) && (0<=f && f<=2000) && x<(f-0.50) && x%5==0) {
		System.out.printf("%.2f",f-x-0.50);
	}
	else {
		System.out.printf("%.2f",f);
	}

}
}

whats wrong here??

#include <stdio.h>

int main(void) {
// your code goes here
int X;float Y;
scanf("%u",&X);
scanf("%f",&Y);
if(0<Y<=2000){
if((X%5==0)&&(Y>=(X+0.50))){
Y=Y-(X+0.5);
printf("%.2f",Y);
}
else{
printf("%.2f",Y);
}
}
return 0;
}

here is the correct answer

#include <stdio.h>

int main(void) {
int x;
float y;
scanf("%d %f",&x,&y);
if(x%5==0 && (y>(x+0.50)))
y=y-x-0.50;
printf("%0.2f",y);
}

can anyone help me where i’m going wrong.??

its y>=(x+0.50)
and take format specifier for x as %u so that it takes only positive integers

#include <stdio.h>

int main(void) {

int x;

float z,y,m;

scanf("%d",&x);// withdraw

scanf("%f",&y);// available

z=x%5;

if(0<x<=2000 && 0<y<=2000 && y>x && z == 0)

{

    m=(y-x)-.50;

    printf("%f",m);

}

else if(z!=0)

{

    printf("%f",y);

}

else if (x<y)

{

    printf("%f",y);

}

return 0;

} showing wrong

[KOTLIN]

import java.util.*

val charge: Float = 0.50f

fun main(args: Array) {
val reader = Scanner(System.in)
var input: Int = reader.nextInt()
var balance: Float = reader.nextFloat()

if (isWithdrawCorrect(input) && isBalanceCorrect(balance) && isAccountBalanced(input, balance) && isMultipleOfFive(input)){
    println("%.2f".format(balance - input - charge))
} else {
    println("%.2f".format(balance))
}

}

fun isAccountBalanced(input: Int,input1: Float): Boolean = (input1 - input - charge) > 0

fun isMultipleOfFive(input: Int): Boolean = (input % 5 == 0)

fun isWithdrawCorrect(withdraw: Int): Boolean = 0 < withdraw && withdraw <= 2000

fun isBalanceCorrect(balance: Float): Boolean = 0 <= balance && balance <= 2000

i dont get it. examples are working fine.

nvm… isAccountBalanced was broken. it needed to be >= 0 not > 0 :smiley:

What is wrong with the code? It gives the correct output with sample cases but upon submission it shows wrong answer.

a,b = map(float, input().split())
if (a+0.5<=b):
if(a%5==0):
print("{:.2f}".format(b-a-0.50))
else:
print("{:.2f}".format(b))
else:
print("{:.2f}".format(b))

The code gives correct output with sample cases but shows wrong answer upon submission. Can anyone please help me with it?

x,y = input().split()
x = int(x)
y = float(y)
if(x%5 == 0 and y>(x+0.50)):
print((y-x-0.5))
else:
print("%.2f" %y)

change that to:

if(x % 5 == 0 and y >= (x + 0.5)):
1 Like

Heres my working solution:

#include <iostream>
using namespace std;

int main() {
int a;
float b;
cin >> a >> b ;

if (a > (b - 0.5)) { cout << b ; }
else if(a % 5 !=0 ) { cout << b; }
else { cout << (b - a - 0.5); } 

return 0;

}

Please Explain why my code is wrong in Custom Input everything is correct but when I submit it says Wrong Answer

import java.util.;
import java.lang.
;
import java.io.*;

/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner scan = new Scanner(System.in);
int w = scan.nextInt();
double a = scan.nextDouble();
if(w % 5 == 0 && w <= a){
double ans = a - w;
ans -= 0.50;
System.out.println(
String.format(“%.2f”, ans));
}
else{
System.out.println(
String.format(“%.2f”, a));
}

}

}

#include
using namespace std;

int main() {
int x;
float y;
cin>>x;
cin>>y;
if(x%5==0 && x>0 && y>0 && x<=y-0.5){
cout<<((y-x)-0.5)<<endl;
}
else{
cout<<y<<endl;
}
return 0;
}

//Atm Problem

#include

#include<bits/stdc++.h>

using namespace std;

int main() {

int a;

double b;



cin>>a>>b;



if((a % 5 == 0) && (b > (a + 0.50))){

    cout<<fixed<<setprecision(2)(b-a-0.50);

}

else{

    

    cout<<fixed<<setprecision(2)<<b;

}



return 0;

}

Can anyone help me, what’s the Error in this code?

Isn’t it supposed to be

b >= (a + 0.50) ?
1 Like

Thank you, Code has been successfully submitted.

#include<bits/stdc++.h>
using namespace std;

int main() {
#ifndef ONLINE_JUDGE

freopen("input.txt", "r", stdin);

freopen("output.txt", "w", stdout);

#endif

int x;
cin >> x; //withdrawl balance

float y;
cin >> y; //Total balance

float result=0;


if ((x % 5 == 0) && (y<x+0.50) {
	result = y - (x + 0.50);

} else {
	result = y;
}


cout << result << endl;
return 0;

}

please explain why it is giving me wrong answer?

link to solution
- YouTube