Archive for September, 2007

Again.. Ninety Nine Bottles of Beers

Saturday, September 22nd, 2007

Here is again.. Ninety Nine Bottles of Beer, C++ style…

#include <iostream>

using namespace std;

const int NINE9=99;
const string n[] = {"bottle", "Ten", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"};
const string o[] = {"Bottle", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"};
const string p[] = {"No more", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"};

inline string s(int i) {return (i>1?"s":"");}
string num(int i) {
        int a = i/10;
        int b = i%10;
        string r="";
        r=(a>1||(a==1&&b==0))?n[a]:(a==1&&b>0?o[b]:"");
        r+=(a==0||(a>1&&b>0))?((r!=""?" ":"")+p[b]):"";
        return r;
}

int main() {
        for (int i=NINE9;i>0;i–)
        {
                cout << num(i) << " " << o[0] << s(i) <<
                        " of beer on the wall, " << num(i) <<
                        " " << n[0] << s(i) << " of beer." << endl;
                cout << "Take one down and pass it around, ";
                cout << num(i-1);
                cout << " " << n[0] << s(i-1) << " of beer on the wall." <<
                        endl << endl;
        }
        cout << p[0] << " " << n[0] << "s of beer on the wall, no more " <<
                n[0] << "s of beer." << endl;
        cout << "Go to the store and buy some more, " <<
                num(NINE9) << " " << n[0] << "s of beer on the wall." <<
                endl;
        return 0;
}

cheers… ^^

My 99 Bottles of Beer

Friday, September 14th, 2007

Just before go to bed.. here is my version of 99 bottles of beer with C++ taste.

And don’t laugh, I know this is very simple.

//compile with gcc or g++
#include <iostream>
using namespace std;
string s(int i)
{return (i>1?"s":"");}
int main()
{
        const int NINE9=99;
        for (int i=NINE9;i>0;i–) {
          cout << i << " Bottle" << s(i) << " of beer on the wall, " <<
                i << " bottle" << s(i) << " of beer." << endl;
          cout << "Take one down and pass it around, ";
          if (i==1) cout << "no more"; else cout <<(i-1);
          cout << " bottle" << s(i-1) << " of beer on the wall." <<
                endl << endl;
        }
        cout << "No more bottles of beer on the wall, no more bottles of beer." << endl;
        cout << "Go to the store and buy some more, " << NINE9
                << " bottles of beer on the wall." << endl;
        return 0;
}

And here is my 99 of anak ayam.. now in C beauty style o_O ;p

#include <stdio.h>
#define e 99
#define o_O {
#define u "satu "
#define c for
#define s "habis "
#define a int
#define O_Ov {
#define t "tinggal "
#define q "%s"
#define T_T ;
#define p "%d\n"
#define v "mati "
#define f ,
#define os "semua.\n"
#define oO ;
#define hm main
#define _o )
#define z printf
#define w "turun "
#define oo "%d, "
#define bye return
#define o 1
#define __ ;
#define GBU 0
#define Oo ?
#define oOo :
#define hm main
#define _ }
#define O 0
#define y "anak "
#define O_o >
#define o_ (
#define x "ayam "
a hm o_ _o O_Ov a b T_T c o_ b=e oO b O_o O __ b– _o o_O z o_ y x w oo v u f b _o oO z o_
q f b O_o o Oo t oOo s os _o oO z o_ p f b O_o o Oo b-o oOo O _o oO _ bye GBU oO _