UVa : 11877 (The Coco-Cola Store)



// http://uva.onlinejudge.org/external/118/11877.html
// Runtime : 0.012
// Algorithm : Ad-hoc

#include <stdio.h>

int main ()
{

    int n;
    while ( scanf ("%d", &n) && n ) {
        int output = 0;
        int full;

        while ( n > 1 ) {
            if ( n == 2 ) { output++; break; }
            full = n / 3;
            output += full;
            n -= n / 3 * 3;
            n += full;
        }

        printf ("%d\n", output);
    }

    return 0;
}

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