Poj Solution 3058

http://poj.org/problem?id=3058

#include <stdio.h>
#include <algorithm>
#include <memory.h>
using namespace std;

int w1[1000000];


int main() {
    int t, i, j, m;
    char c, temp;

    scanf( "%d", &t );
    getchar();

    while( t-- ) {

        m = 0;

        while( 1 ){
            c = getchar();
            
            if( c == 'n' )
                break;
            
            if( c >= '0' && c <= '9' ) {
                j = 0;
                while( c >= '0' && c <= '9' ) {
                    j = j*10 + c-'0';
                    c = getchar();
                }
                while( --j ) {
                    w1[m] = (temp<<20)|m;
                    m++;
                }

                ungetc( c, stdin );
            }
            else {
                w1[m] = (c<<20)|m;
                m++;
            }

            temp = c;
        }

    
        sort( w1, w1+m );

        for( j = (w1[0]&((1<<20)-1)), i=0; i<m; i++ ) {
            printf( "%c", w1[j]>>20 );
            j = (w1[j]&((1<<20)-1));
        }
        printf( "n" );

    }
    return 0;
}



											
This entry was posted in poj. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *