Computer Programming Contest Preparation

ToolBox - Source for: 4/482/UVa482.java



/home/toolbox/public_html/solutions/4/482/UVa482.java
    1 import java.io.BufferedReader;
    2 import java.io.InputStreamReader;
    3 
    4 
    5 public class UVa482
    6 {
    7     public static void main (String args[]) throws Throwable
    8     {
    9         BufferedReader in =  new BufferedReader( new InputStreamReader(System.in));
   10         for(int  i = 0, C = Integer.parseInt(in.readLine().trim()); i < C ; ++i)
   11             {
   12                 //read an empty line
   13                 in.readLine();
   14 
   15                 //read the two strings
   16                 String permutedArray[] =  in.readLine().trim().split(" "),
   17                 toPermute[] = in.readLine().trim().split(" "),
   18                 sol [] =  new String[toPermute.length];
   19                 int length = toPermute.length ;
   20                 //fill the solution as per xpi = xi
   21                 for(int k = 0 ; k < length ; ++k)
   22                     sol[Integer.parseInt(permutedArray[k]) - 1] = toPermute[k];
   23 
   24                 //display the solution
   25                 for(int k = 0  ; k  < length ; ++k) System.out.println(sol[k]);
   26                 if(i<C-1)System.out.println();
   27 
   28             }
   29 
   30     }
   31 }
   32 
   33