Codechef Practice Easy – ATM

Problem Code: HS08TEST

The initial solution in C to this problem seemed okay to me, and so it did to the codechef engine.

#include<stdio.h>
int main()
{
int wd; //withdraw amount
float bal; //initial account balance
scanf("%d%f",&wd,&bal);
if(bal-wd>=0.5 && wd%5==0) //enough balance for bank charge, and withdrawal amount multiple of 5.
printf("%0.2f",bal-wd-0.5); //print new balance.
else
printf("%0.2f",bal); //if not enough money, print current account balance.
return 0;
}

1st Attempt – Accepted – 0.0 Time – 1.6M Memory

Codechef Practice Easy: Life, the Universe, and Everything

Problem code = TEST

Initial solution – Accepted – 0.01 Time – 2.2M Memory

#include<stdio.h>
 int main()
 {
 int num;
 scanf("%d",&num);
 while(num!=42){
 printf("n%d",num);
 scanf("%d",&num);
 }
 return 0;
 }

Lets optimize the code a bit further.
2nd Attempt – Accepted – 0.0 Time – 2.2M Memory

#include<stdio.h>
 int main() {
 int x;
 while(1){
 scanf("%d",&x);
 if(x==42)
 break;
 else
 printf("%dn",x);
 }
 return 0;
 }

Now that was an easy warm-up to the codechef engine. I’ll move on to the next problem and try to solve all the problems in the practice-easy section whenever I get some free time.