ACM (UVa) : 11371


// http://uva.onlinejudge.org/external/113/11371.html

#include <stdio.h>
#include <stdlib.h>

int main ()
{
    char a [15];

    while ( scanf ("%s", a) != EOF ) {

        for ( int i = 0; a [i] != 0; i++ ) {
            for ( int j = i + 1; a [j] != 0; j++ ) {
                if ( a [i] < a [j] ) {
                    a [i] ^= a [j];
                    a [j] ^= a [i];
                    a [i] ^= a [j];
                }
            }
        }

        double first = atof (a);

        for ( int i = 0; a [i] != 0; i++ ) {
            for ( int j = i + 1; a [j] != 0; j++ ) {
                if ( a [i] > a [j] ) {
                    a [i] ^= a [j];
                    a [j] ^= a [i];
                    a [i] ^= a [j];
                }
            }
        }

        if ( a [0] == '0' ) {
            for ( int i = 1; a [i] != 0; i++ ) {
                if ( a [i] != '0' ) {
                    a [0] ^= a [i];
                    a [i] ^= a [0];
                    a [0] ^= a [i];
                    break;
                }
            }
        }

        double second = atof (a);

        printf ("%0.lf - %0.lf = %0.lf = 9 * %0.lf\n",
        first, second, first - second, (first - second)/9);

    }

    return 0;
}

2 thoughts on “ACM (UVa) : 11371

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