Thursday, June 2, 2016

UVA problem 10935- Throwing cards away I : soution

Unknown
# include <cstdio>
# include <queue>
using namespace std;
int main ()
{
    int n, x;
    queue< int > q;
    while (scanf("%d",&n), n)
    {
        for ( int i = 1 ; i <= n; i++)
        q. push (i);
        printf ("Discarded cards:" );
        while (q.size () > 1 )
        {
        printf (" %d" , q.front());
        q.pop();
        x = q.front();
        q.pop ();
        if (!q. empty())
        printf ("," );
        q. push (x);
        }
        printf ("\nRemaining card: %d\n" , q. front());
        q. pop ();
    }
    return 0 ;
}

Unknown

Studying at Shahjalal University of Science and Technology, Sylhet.

0 comments:

Post a Comment

Coprights @ 2016,