HS08TEST - Editorial

what is wrong in my code?

#include<stdio.h>
#include

using namespace std;
int main()
{
float y,z,w;
int x;
scanf("%d%f",&x,&y);
if(y<=0 || y>2000.00){
cout<<“0.00\n”;
}
else if(x>0 && x%5==0 && x<y){
w =(x+0.50);
z =y-w;
printf("%.2f\n",z);
}
else{
printf("%.2f\n",y);
}

return 0;

}

Double declaration of k

Float amt not atm

def atm(num1, num2):
y = int(num1)
z = float(num2)
lastdig = int(repr(y)[-1])
if y>z or y==z:
return(format(z, ‘.2f’))
else:
if lastdig == 0 or lastdig==5:
m = float(z-y-0.50)
return(format(m, ‘.2f’))

    elif lastdig != 0 or lastdig != 5:
        return(format(z, '.2f'))

moneydraw, moneyin = input("").split()
print(atm(moneydraw, moneyin))

I wrote this Python code and when I submit it, it states that it is wrong but whenever I run it on my computer or on the codechef IDLE it works very well

#include <stdio.h>

int main(void) {
int x;
float a;
scanf("%d",&x);
scanf("%f",&a);
if(x>0 && x<=2000)
{ if(x%5==0 && x<=a)
{
a=a-x-.5;
printf("%.2f",a);
}
else if (x%5!=0 || (x+0.5)>a)
printf("%.2f",a);
}
return 0;
}
what is wrong with my code?

there would be -0.5 not +0.5

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

but it shows wrong ans??

use bufferedreader instead of scanner

yes

That was asked 5 years ago

1 Like

cook your dish he

amount=0
balance=0
inp=’’
try:
inp=input()
if len(inp)!=0 and len(inp.strip())!=0:
amount, balance = inp.split(" “)
except Exception as e:
pass
amount = int(amount)
balance = int(balance)
if 0<=amount<=2000 and 0<=balance<=2000:
print(amount,end=” “)
print(balance)
if amount%5==0 and amount+0.5<balance:
balance=balance-amount
balance=balance-0.5
else:
balance=0
print(”{:.2f}".format(balance))

why i’m getting wrong answer when i submit,i tested all possible cases and fixed errors

# cook your dish here
# lol
remaining = 0.00
total = 0
try:
    x,y = input().split(" ")
    x = int(x)
    y = float(y)
    
    if x%5 == 0:
        total = x + 0.50
        if y >= total:
            remaining = float(y-total)
        else:
            remaining = float(y)
    else:
        remaining = float(y)

except Exception as e:
   pass

print('%.2f' %remaining)
#lmao

I don’t why I’m getting a wrong answer when submitting. I’ve tried everything I can.

For Python. showing NZEC error for below code.

Account_balance = 2000

withdraw = int(input("Pooja want to withdraw : "))

if withdraw>Account_balance or withdraw<0:
    print(f'Insuficient balance : {Account_balance}')
    
elif withdraw % 5 !=0:
    print(f' Present balance : {Account_balance}')
    
else:
    Balance = Account_balance - withdraw - 0.5
    print(f'Transcation Completed. Present balance : {Balance}')

Try this one:
#include<bits/stdc++.h>
using namespace std;
int main() {
int x;
float y;
cin>>x>>y;
if(y<x)
cout<<y;
else if(x%5!=0 || (x+0.5)>y)
cout<<fixed<<setprecision(2)<<y;
else {
cout<<fixed<<setprecision(2)<<y-x-0.50;
}
return 0;
}

1 Like

make sure you guys note that for every transaction it costs you 0.50

my Java code : `

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

/* 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);
	double a_bal = 0.50; //bank transaction charge
	long x=sc.nextLong();
	double b=sc.nextDouble();
	if((x%5==0) && b-a_bal>=x){ 
	    double remaining=b-x-a_bal; // here b-a_bal is mentioned because balance should be greater than 0.50 for withdrawl
	    	System.out.println(String.format("%.2f", remaining));
	}
	else{
	    System.out.println(String.format("%.2f", b));
	}

}

}
`

#include
#include
using namespace std ;
int main ( )
{
long withDraw ;
float accBalance , remaining ;
cin>>withDraw>>accBalance ;
if ( withDraw % 5 == 0 )
{
if ( withDraw < accBalance )
{
remaining = withDraw + 0.50 ;
cout<<fixed;
cout<<setprecision(2)<<accBalance-remaining ;
}
else
{
cout<<fixed;
cout<<setprecision(2)<<accBalance ;
}
}
else
{
cout<<fixed;
cout<<setprecision(2)<<accBalance ;
}
return 0 ;
}

Plz tell whats wrong it showing wrong answer

Can anyone plss tell me why when i m uploading this,it is considering it wrong but on my offline compiler it’s running flawlessly.

#include
#include<math.h>
#include
using namespace std;
int main(){
float bal1,bal2,witdraw;
cin>>witdraw>>bal1;
if((fmod(witdraw,5) == 0) && (bal1 > witdraw)){
bal2 = fabs(bal1 - witdraw);
cout<<fixed<<setprecision(2)<<bal2;
}
else
cout<<fixed<<setprecision(2)<<bal1;
return 0;
}

try:
balance = float(input("enter the balance: "))
withdraw = float(input("enter the amount to be withdraw: "))
fees=0.50
amount=0.0
if(withdraw > balance and withdraw%5==0):
print(“insufficient funds”,balance)
elif(withdraw%5==0):
amount=(balance-withdraw-fees)
print(“the amount is”,amount)
else:
print(“balance”,balance)
except:pass

WHATS WRONG !
i used try: because it was showing nzec error… and now its says wrong answer

(n, k) = map(int, input().split())
if(float(n)%5==0):
print(float(k)-float(n)-0.50)
else:
print(float(k))

OR

x=list(input().split())
if(float(x[0])%5==0):
print(float(x[1])-float(x[0])-0.50)
else:
print(float(x[1]))

both gives me NZEC error what is the problem

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeChef_ATM
{
    class Program
    {
        static void Main(string[] args)
        {

            /* Made by Stefan Stojanovic [Alisp] 
            using .NET Visual Studio Community 2019 16.8.1*/

            // User input for bank account and withdrawal amount
            Console.WriteLine("Input how much money you have in the bank acount and how much you would like to withdraw. The Bank takes 0.5$ as tax.");
            Console.WriteLine("Example: '200' '99'");
            Console.Write("(Account)(Withdrawal): ");
            string[] userInput = Console.ReadLine().Split(' ');

            // Current account balance.
            double trueaccount = Convert.ToDouble(userInput[0]);
            double accounttracker = trueaccount;

            // Withdrawal amount.
            double truewithdraw = Convert.ToDouble(userInput[1]);

            // Check if multiple of 5.
            if (truewithdraw % 5 == 0)
            {
                Console.WriteLine("Withdrawal must me a multiple of 5. Example: 54,36,29...");
                Console.WriteLine("Try Again.");
                Console.ReadLine();
                return;
            }

            // Check if there is enough available money.
            if (truewithdraw + 0.5 > trueaccount) 
            {
                Console.WriteLine("You can't withdraw more than available money from the account.");
                Console.WriteLine("Try Again.");
                Console.ReadLine();
                return;
            }

            // Calculating the withdrawal.
            trueaccount -= truewithdraw;
            trueaccount -= 0.50;

            // Result.
            Console.WriteLine($"The amount of money you had in the account: {accounttracker}$");
            Console.WriteLine($"The amount of money you have currently: {trueaccount}$");

        // End.
        Console.ReadLine();
        }
    }
}

Can anybody tell me what’s wrong here, please?