/* * UVA_10978.CPP * * Created on: 2013年10月6日 * Author: Administrator */ #include <iostream> #include <cstdio> #include <cstring> using namespace std; int main(){ char card[55][55],word[55][55],*order[55]; int n; while(scanf("%d",&n)!=EOF,n){ int i,j,k; for(i = 0 ; i < n ; ++i){ order[i] = "?"; } for(i = 0 ; i < n ; ++i){ scanf("%s %s",&card[i],&word[i]); } for(i = 0,j = 0 ; i < n ; ++i){ for(k = strlen(word[i]) ; ; j = (j + 1)%n ){ if(order[j] == "?" && --k <= 0){ break; } } order[j] = card[i]; } for(i = 0 ; i < n ; ++i){ printf(i < n - 1 ?"%s ":"%s ",order[i],order[i] ); } } }