I don’t know how I missed this. This video was made for JavaOne 2011 celebrating the ‘Java Life’, dedicated to homies everywhere who code hard day and night. *like-a-boss*
Monthly Archives: April 2014
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
11th Grade Activity Usefulness
I guess this sums it all up. *wink*
Codechef Practice Easy: Life, the Universe, and Everything
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.
Hello World
Hello world?
I’ve always wondered why this was the first thing people write when trying out something new.
Much like every other question possibly related to code, someone had already asked this question on Stack Overflow.
Apparently the very first ‘Hello World’ program was written by Brian Kernighan as part of the documentation for I/O section of the BCPL programming language manual. This code was also used for testing of the C compiler and hence made its way into Kernighan and Dennis Ritchie’s book on C which was published in 1972. And again, later, it was also one of the first programs used to test Bjarne Stoustroup’s C++ compiler.
Ha! Brian Kernighan, Dennis Ritchie, and Bjarne Stoustroup! No wonder people have been using it ever since.
Anyway!
Hello World!