HS08TEST - Editorial

/* 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 atm(int amount , double balance){

    double charges = 0.50;
    
    double res = 0.00;
    
    if (amount % 5  == 0){
        
        if(balance >= amount){
            
            res = balance - amount - charges;
            
           System.out.println(res);
        }
        else{
           System.out.println(balance);
            
        }
    }
   
    else{
        
    
           System.out.println(balance);
       
        
       
    }
    
}



public static void main (String[] args) throws java.lang.Exception
{   
             Scanner sc = new Scanner(System.in);
	int amount = sc.nextInt();
	double balance = sc.nextDouble();
	
	atm(amount,balance);
	
	
	
	
	
}

}

whats wrong with this code?after clicking on submission button it is saying wrong code…Why?

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

int main()
{

int x;
float y;
cin >> x ;
cin >> y;
if ((x<=2000 && x>0) && (y<=2000.00 && y>0.00))
{
if ((y>(x+0.50)) && x%5==0)
{
float final=(y-(x+0.50));
cout << fixed << setprecision(2)<<final;
}
else{
cout <<fixed<<setprecision(2)<<y;
}
}
return 0;
}

what’s wrong here??

#include
using namespace std;
int main() {
int x;
double y,r=0.00;
cin >> x;
cin >>y;
if(y>(x+0.50) && x%5==0){
r=y-x-0.50;
printf("%0.2f",r) ;
}
else {
printf("%0.2f",y);
}
return 0;
}
please tell me why it’s showing wrong status ??
it is running successfully , so why ?

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

int main() {
int amt;
double bal;
cin>>amt;
cin>>bal;
if(amt>bal)
cout<<bal;
else if(amt%5==0&&(amt+0.5)<bal)
{

    cout<<fixed<<setprecision(2)<<bal-amt-0.5;
}
else
{
    cout<<fixed<<setprecision(2)<<bal;
}

}

what is the problem in this solution??

what is wrong in this? The output is correct in vsc but it still says wrong answer.

    #include <stdio.h>

    int main()

    {

        int wa;

        float bal;

        scanf("%d%f", &wa, &bal);

        if ((wa % 5 == 0) && (bal > (wa + 0.5)))

        {

            printf("%.2f", bal - (wa + 0.5));

        }

    }

Hi,

I have been getting an error in this code every time I run it. Is something wrong with the code? I think I might be facing problems using the custom input maybe.

x = int(input("The amount of cash to be withdrawn: "))
y = int(input("Initial account balance: "))

bank_charges = 0.50
if (x%5 == 0):
y = y - x - bank_charges
print(y)
else:
print(y)

Can anyone help me diagnose the problem here? I know I should be specific with what error I am getting but I change a few things and try again and the error lines changes.

Got no idea WTH it’s not submitting. PLS help.

class Codechef
{
public static void main (String[] args)
{
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
double balance = scanner.nextDouble();
double result;

if (n % 5 == 0 && n < balance){ result =(balance - n) - 0.5;
    System.out.println(result);}
if (n % 5 != 0 && n+0.5<= balance){
    System.out.println(balance);}
else if (n>balance || n+0.5>balance){
    System.out.println("Insufficient transaction");}

}
}

Suppose the input is 120 120.00 then your code gives the output -0.50. Check for that case also. Answer for this case should be 120.00

#include
#include
using namespace std;

int main() {
// your code goes here
unsigned int am;
float bal;
cin>>am;
cin>>bal;
if(0<am&&am<=2000&&0<=bal&&bal<=2000)
{
if(am<bal&&am%5==0)
{bal=bal-am-0.50;
cout<<setprecision(2)<<fixed<<bal<<endl;
}
else if((am+0.5)<=bal)
{bal=bal-am-0.5;
cout<<setprecision(2)<<fixed<<bal<<endl;
}
else
cout<<setprecision(2)<<fixed<<bal<<endl;

}
return 0;

}

It is giving correct output but while submitting it is showing wrong answer. please tell me what is the issue related to it.

#include <stdio.h>

int main()
{
const float charge = .5;
float balance = 0;
int withdraw = 0;
int check = 0;

scanf("%d %f", &withdraw, &balance);

if (withdraw % 5 == 0)
	check = 1;

if (withdraw <= balance && check && balance >= 5.5)
	balance = balance - (withdraw + charge);

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

return 0;

}

I get the right inputs but when I try to submit it the programs say I get the wrong solution and I don’t know why.

To all the people facing issues with NZEC, or nullPointer.
Try adding a check for null input like below.
Apparently the testing run passes null input.

	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String inpt = br.readLine();
	if (null != inpt) {
		String[] inptArr = inpt.split(" ");
		int X = Integer.parseInt(inptArr[0]);
		double Y = Double.parseDouble(inptArr[1]);

		if ((X + 0.50) < Y && X % 5 == 0)
			Y = Y - (X + 0.50);

		System.out.printf("%.2f", Y);
	}
	br.close();
}

X, Y = input(’’).split()
X = float(X)
Y = float(Y)
if X%5 == 0 and X + 0.5 < Y:
Y=Y - X - 0.50
else:
Y=Y

print(Y)
why is this not working?

#include

using namespace std;

int main()

{

int y,x;

cin>>x>>y;

if ( (x%5==0) && (x < (y+.50)))

cout << (y - x) - 0.50;

else

cout<<y;

return 0;

}

//----> what is wrong in this? why my memory limit is exceeding and it is showing approx15000kb?

You have to return value not print.

x,y=input().split()
y=float(y)
x=float(x)

if (x%5==0.00 and x>0 and y>=0 and x<=2000 and y<=2000):
if (float(x)<(y-0.50)):
print(f"{(y - float(x) - 0.50):.2f}",)
else:
print(f"{y:.2f}")
else:
print(f"{y:.2f}")

it shows error

you look new in competitive programming as you use printf. Its good think to add printf and make your code beautifull but its not needed in competitive programming though.

#include
using namespace std;

int main() {
// your code goes here

//variables
int X, Y; // X is need, Y is balance
float fee = 0.5; // bank fee
cin >> X >> Y; // reads and stores X and Y
float fx = X; // turns them into floats
float fy = Y;

if( X%5 == 0)//Checks if need is divisible by 5
{
    if( X < Y) // checks if X is less than balance
    {
        fy -= fx;
        fy -= fee;
        printf("%.2f", fy); // prints new balance
    }
    else // if x is greater prints old balance
    {
        printf( "%.2f", fy); 
    }
    
}
else // if x is not divisible by 5, prints out old balance
{
    printf( "%.2f", fy);  
}

return 0;

}

(This solution was longer than all the ones i saw but it worked well for me, when i kept custom inputs it always worked but once i submitted it it always marked it as wrong. It executes in under 1 second and uses 15.232 kb)

Why take the inputs into Integers when it is mentioned that Y will be a Number?

It should have been if(X + fee <= Y) instead.

#include
using namespace std;

int main() {
int x, tot;
float bal;
cin>>x>>tot;

if (x  <= tot- 0.5 )
{
    if (x%5==0)
    bal= tot- x - 0.5;
   
}

else 
{
  bal= tot;
  
}
cout<<"\n"<<bal;

}

Program is showing correct output as given but while submission, it is showing wrong…
Why??

You should at least read the previous comments before blindly posting your code and asking for help.

1 Like