HS08TEST - Editorial

PROBLEM LINK:

Practice

Author: ADMIN

Editorialist: SUSHANT AGARWAL

DIFFICULTY:

CAKEWALK

PREREQUISITES:

Basic looping,Basic Input/Output,Data Types

EXPLANATION:

Please refer to the sample solution given by editorialist.

EDITORIALIST’S SOLUTION:

Editorialist’s solution can be found here.

2 Likes

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

8 Likes
#include<stdio.h>
int main()
{
	unsigned int x; //amount withdrawn
	float y; //bank balance
	scanf("%d%f", &x,&y);
	if(x>0&&x<=2000&&y>0&&y<=2000)
	{
	
		if(x>y&&x%5==0)
			printf("%0.2f", y);
		else if(x%5==0)
		{
			y=(y-x)-0.5;
			printf("%0.2f", y);
		}
		else
			printf("%0.2f", y);
	}
getchar();
return 0;
}
5 Likes

#include<stdio.h>

main()

{

int i;
float k,j;
scanf("%d",&i);
scanf("%f",&j);
if (0<i&&i<=2000 && 0<=j&&j<=2000)
{

if (i%5!=0||i>j)
k=j;
else 
k=j-0.50-i;
printf("%.2f",k);
}
return 0;

}

can anyone tell why this is wrong??

1 Like

#include<stdio.h>
int main(){
unsigned int amt;
float atm=0.5,bal,rlt;
scanf("%u %f",&amt,&bal);
if((bal+atm)>=amt && amt%5==0 && (0<=bal<=2000) && (0<amt<=2000))
rlt=bal-(amt+atm);
printf("\n%.2f",rlt);
return 0;
}

whats wrong in this?

import java.util.Scanner;

/**
*

*/
class ATM {

public static void main(String[] args) {
    
    float currentBal = 120;
    int withdrawAmt;
    float charge = (float) 0.50;
    
    Scanner s = new Scanner(System.in);      
     withdrawAmt = s.nextInt();
     
     if(withdrawAmt % 5 == 0 && withdrawAmt > 0.00 && withdrawAmt < 2000.00)
     {         
        if(withdrawAmt + 0.5 < currentBal)
        {
                currentBal = currentBal - withdrawAmt - charge;
                System.out.printf("%4.2f\n", currentBal);
        }
        else
        {
               System.out.printf("%4.2f\n", currentBal);
        }
    }
    else
    {
           System.out.printf("%4.2f\n", currentBal);
    }
}

}

what is wrong in this?
its giving perfect output in my system

#include<iostream.h>
int main()
{int x,y;
cin>>x;
cin>>y;
if(x>y||x%5!=0)
cout<<y;
else
cout<<y-x-0.5;
return 0;
}
plz tell what’s wrong in this code??why can’t i include iostream.h

3 Likes

import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("#.00");
final double ch=0.50;
int WdAmnt =input.nextInt();
Double PrevBalnc=input.nextDouble();
boolean flag = false;
if(WdAmnt%5 ==0 && WdAmnt<=2000 && PrevBalnc <=2000.00 && WdAmnt>0 && PrevBalnc>=0.00)
flag=true;
else
flag=false;
if(WdAmnt!=0 && WdAmnt<=PrevBalnc && flag)
{
PrevBalnc=PrevBalnc-(WdAmnt+ch);
}
System.out.println( df.format(PrevBalnc));
}

125**What is wrong with this code?**125

#include <stdio.h>

int main() {

int amt;
float bal, a_bal;
a_bal = 0.50;
scanf ("%d %f", &amt, &bal);
if ((amt%5 == 0) && (amt <= bal))
	printf ("%.2f\n", (bal-amt-a_bal));	
else
	printf ("%.2f\n", bal);	
return 0;

}
Its giving wrong answer while submitting, can any one help…
its giving perfect output on my system

#include <stdio.h>

int main()
{
	double total_sum;
	int withdraw;
	double charges = 0.5;
	double withdraw_fin;
	
	scanf("%d %lf", &withdraw, &total_sum);
	
	if(withdraw <= total_sum)
	{
		if(withdraw % 5 == 0)
		{
			withdraw_fin = (total_sum - withdraw) - charges;
			printf("%.2lf\n", withdraw_fin);
		}
		else
		{
			printf("%.2lf\n", total_sum);
		}
	}

	else
	{
		printf("%.2lf\n",total_sum);
	}
	return 0;
}

It’s giving me wrong answer, but it works perfectly on my system giving me the correct output.

3 Likes

Terima kasih dan salam kenal.
codechef Link

code Link

import java.io.;
import java.util.
;

class TEST2{

public static void main(String args[])throws IOException{

	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	PrintWriter pw = new PrintWriter(System.out, true);
	double initialAmount,widthdrawal;


	widthdrawal = Integer.parseInt(br.readLine());
	initialAmount = Integer.parseInt(br.readLine());

	try{


			if(widthdrawal < initialAmount){

				if( (widthdrawal%5) == 0 ){

						double balance = ((initialAmount - widthdrawal) - 0.50);
						pw.println(String.format("%.2f",balance));
				}else{

						pw.println(String.format("%.2f",initialAmount));
											
				}


			}else{

				pw.println(String.format("%.2f",initialAmount));
				
			}

	}catch(Exception e){

		System.exit(0);
	}

	System.exit(0);


	

}

}

giving the desired output on my machine…on codechef its showing runtime error NZEC…please help in figuring out whats wrong with the code???

6 Likes

#include<stdio.h>

int main()
{
int x,temp;
float remain,ini;
scanf("%d%f",&x,&ini);
temp=x%5;

if((0<x<=2000)&&(0<=ini<=2000)&&(x<ini)&&(temp==0))
{
 remain=ini-(x+0.50);
 printf("%0.2f",remain);	
}
else 
if((temp!=0)||(x>ini))
{
	remain=ini;
	printf("%0.2f",remain);
}
return 0;

}

tell me what is wrong in it.

1 Like

Can somebody please explain what’s wrong with the following code? It is running fine in my machine and I am getting runtime error here.

class HelloWorld{

 public static void main(String []args){

double i=Double.parseDouble(args[0]);

double j=Double.parseDouble(args[1]);
double n=j-i-0.50;
System.out.print(n);

 }

}

#include
using namespace std;
int main()
{
int with;
float bal ,c;
c = ((bal-with) -0.50);
cin>>with>>bal;
if (with > 0 && with <=2000 && bal >= 0 && bal <= 2000)
{ if((with > bal) || (with % 5 != 0))
cout<<bal<<endl;
else if (with % 5 == 0)
cout<<c;}
return 0;
}

What am I doing incorrectly?

1 Like

import java.io.*;
import java.text.DecimalFormat;
import java.util.Scanner;
class cheftry2{
public static void main(String Args[]) throws IOException
{
double y; int x;
Scanner in = new Scanner(System.in);
//DataInputStream dis = new DataInputStream(System.in);
x=in.nextInt();
y=in.nextDouble();

		//x=Integer.parseInt(dis.readLine());
		//y=Float.parseFloat(dis.readLine());
		DecimalFormat df = new DecimalFormat("0.00");
		df.setMaximumFractionDigits(2);
		df.setMinimumFractionDigits(2);
		if(x> 0 && x<=2000)
		{
			if((x % 5)==0)
				System.out.println(df.format((y-x)-0.50));
			else
            {
                System.out.println(y);
            }
        }
        else
            {
                System.out.println(y);
            }
}

}

Whats WRONG in this code…??? please help me.

@anianand92
There is one thing to notice.
Every transaction cost you 0.5 rupees as transaction fees.
So you cannot withdraw money if (x>=y-0.5)
You must have additional 0.5 ruppes in your account.

4 Likes

#include
#include
using namespace std;

int main()
{ int x;
float y;
cin>>x>>y;
float f=(y-x-0.50);
if(x%5==0 && y>x)
{ cout<<fixed;
cout<<setprecision(2)<<f;
}
else
{
cout<<fixed;
cout<<setprecision(2)<<(y);
}
return 0;
}

#include<stdio.h>
int main ()
{
float x , y ;
scanf("%f%f",&x,&y);
if (x<y && ((int)x)%5==0)
y=y-x-0.5;

 printf("%0.2f",y);
 return (0);

}

/* whats wrong in this???

@prerak13
if (x<y && x%5==0)
y=y-x-0.5;—>wrong

if(x-0.5<=y and x%5==0) then only the withdrawl can be made.