UVa : 10101


#include <algorithm>
using namespace std;

bool kuti;
bool space;

void convert (char *temp)
{
    if ( strcmp (temp, "0000000") == 0 )
        return;

    char x [3];
    x [0] = temp [0];
    x [1] = temp [1];
    x [3] = 0;

    int number = atoi (x);

    if ( number ) {
        if ( space ) printf (" ");
        space = true;
        printf ("%d lakh", number);
    }

    // hazar
    x [0] = temp [2];
    x [1] = temp [3];
    x [3] = 0;

    number = atoi (x);

    if ( number ) {
        if ( space ) printf (" ");
        space = true;
        printf ("%d hajar", number);
    }

    x [0] = temp [4];
    x [1] = 0;

    number = atoi (x);

    if ( number ) {
        if ( space ) printf (" ");
        space = true;
        printf ("%d shata", number);
    }

    x [0] = temp [5];
    x [1] = temp [6];
    x [3] = 0;

    number = atoi (x);

    if ( number ) {
        if ( space ) printf (" ");
        space = true;
        printf ("%d", number);
    }

    kuti = true;
}

int main ()
{
    char input [20];
    int cases = 0;

    while ( gets (input) ) {
        printf ("%4d. ", ++cases);

        kuti = false;
        space = false;

        if ( strcmp (input, "0") == 0 ) {
            printf ("0\n");
            continue;
        }

        int length = strlen (input);
        reverse (input, input + length);

        for ( int i = length; i < 15; i++ )
            input [i] = '0';
        input [15] = 0;

        reverse (input, input + 15);

        if ( input [0] - '0' ) {
            printf ("%d kuti", input [0] - '0');
            kuti = space = true;
        }

        char temp [10];
        for ( int i = 1; i <= 7; i++ )
            temp [i - 1] = input [i];
        temp [7] = 0;

        convert (temp);

        if ( kuti )
            printf (" kuti");

        for ( int i = 8; i < 15; i++ )
            temp [i - 8] = input [i];
        temp [15] = 0;

        convert (temp);

        printf ("\n");
    }

    return 0;
}

One thought on “UVa : 10101

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