HDU : Hastiness


// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <sstream>
#include <set>
#include <math.h>
#define pi acos(-1.0)
#define N 1000000
using namespace std;


int main ()
{
    int input;

    while ( scanf ("%d", &input) != EOF ) {
        int thousand = input / 1000;
        input %= 1000;
        int hundred = input / 100;
        input %= 100;
        int decade = input / 10;
        int unit = input % 10;

        string t = "";
        string h = "";
        string d = "";
        string u= "";

        switch (thousand) {
            case 1:
                t += "one";
                break;
            case 2 :
                t += "two";
                break;
            case 3 :
                t += "three";
                break;
            case 4 :
                t += "four";
                break;
            case 5 :
                t += "five";
                break;
            case 6 :
                t += "six";
                break;
            case 7 :
                t += "seven";
                break;
            case 8 :
                t += "eight";
                break;
            case 9 :
                t += "nine";
                break;
        }

        if ( t.length () ) {
            t += " thousand";
        }

        switch (hundred) {
            case 1:
                h += "one";
                break;
            case 2 :
                h += "two";
                break;
            case 3 :
                h += "three";
                break;
            case 4 :
                h += "four";
                break;
            case 5 :
                h += "five";
                break;
            case 6 :
                h += "six";
                break;
            case 7 :
                h += "seven";
                break;
            case 8 :
                h += "eight";
                break;
            case 9 :
                h += "nine";
                break;
        }

        if ( h.length () ) {
            h += " hundred";
        }

        switch (decade) {
            case 1:
                switch (unit) {
                    case 0 :
                        d += "ten";
                        break;
                    case 1:
                        d += "eleven";
                        break;
                    case 2 :
                        d += "twelve";
                        break;
                    case 3 :
                        d += "thirteen";
                        break;
                    case 4 :
                        d += "fourteen";
                        break;
                    case 5 :
                        d += "fifteen";
                        break;
                    case 6 :
                        d += "sixteen";
                        break;
                    case 7 :
                        d += "seventeen";
                        break;
                    case 8 :
                        d += "eighteen";
                        break;
                    case 9 :
                        d += "nineteen";
                        break;
                }
                break;
            case 2 :
                d += "twenty";
                break;
            case 3 :
                d += "thirty";
                break;
            case 4 :
                d += "forty";
                break;
            case 5 :
                d += "fifty";
                break;
            case 6 :
                d += "sixty";
                break;
            case 7 :
                d += "seventy";
                break;
            case 8 :
                d += "eighty";
                break;
            case 9 :
                d += "ninety";
                break;
        }

        switch (unit) {
            case 1:
                u += "one";
                break;
            case 2 :
                u += "two";
                break;
            case 3 :
                u += "three";
                break;
            case 4 :
                u += "four";
                break;
            case 5 :
                u += "five";
                break;
            case 6 :
                u += "six";
                break;
            case 7 :
                u += "seven";
                break;
            case 8 :
                u += "eight";
                break;
            case 9 :
                u += "nine";
                break;
        }

        if ( decade == 1 )
            u = "";

        string output = "";

        output += t;

        if ( h.length () ) {
            if ( t.length () )
                output += " and ";
            output += h;
        }

        if ( d.length () ) {
            if ( t.length () || h.length () )
                output += " and ";
            output += d;
        }

        if ( u.length () ) {
            if ( d.length () ) {
                output += '-';
                output += u;
            }
            else if ( t.length () || h.length () ) {
                output += " and ";
                output += u;
            }
            else
                output += u;
        }

        if ( !output.length () )
            output += "zero";
        cout << output << endl;
    }

    return 0;
}

// @END_OF_SOURCE_CODE

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s