2014年4月22日 星期二

UVa 12650 - Dangerous Dive

Problem link

Keyword: ad hoc

Algorithm:

Use an array to keep track of all conditions. Then output the result.

Code:
#include<cstdio>

int main()
{
    int all, back, tmp;

    while( scanf( "%d %d", &all, &back ) == 2 )
    {
        bool state[ 10001 ] = { false };
        for( int i = 0; i < back; ++i )
            scanf( "%d", &tmp ), state[ tmp ] = true;
        if( all == back )
            putchar( '*' );
        else
            for( int i = 1; i <= all; ++i )
                if( !state[ i ] )
                    printf( "%d ", i );
        puts( "" );
    }

    return 0;
}

沒有留言:

張貼留言