1.
/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, WS10/11
* Problem: ##11385 ## Da Vinci Code
* Link: http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2380
*
* @author Felix Dietrich
* @version 1.0, 15.10.2010
*
* Method : Simulation, HashMap
* Status : Accepted
* Runtime: 0.292
*/
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main
{
public static void main(String... s)
{
Long[] fibs = new Long[100];
Map<Long,Integer> fibmap = new HashMap<Long,Integer>();
char[] decstring = new char[100];
fibs[1] = new Long(1);
fibs[2] = new Long(2);
fibmap.put(fibs[1], 1);
fibmap.put(fibs[2], 2);
// create all fib numbers up to the maximum possible for long
for(int i=3; i<92; i++)
{
fibs[i] = fibs[i-1] + fibs[i-2];
fibmap.put(fibs[i],i);
}
Scanner sc = new Scanner(System.in);
int testcases = sc.nextInt();
for(int tc = 0; tc<testcases; tc++)
{
int N = sc.nextInt();
long[] fnums = new long[N];
int maxn = 0;
// read fib numnbers and determine the length of the result string
for(int n=0; n<N; n++)
{
fnums[n] = sc.nextInt();
if(maxn < fibmap.get(new Long(fnums[n])))
{
maxn = fibmap.get(new Long(fnums[n]));
}
}
String encstr = "";
while(encstr.length() < N)
encstr = sc.nextLine();
// get only the uppercase letters out of the encrypted string
char[] uppercases = new char[N];
for(int i=0;i<N;i++)
{
while(!Character.isUpperCase(encstr.charAt(0)))
encstr = encstr.substring(1);
uppercases[i] = encstr.charAt(0);
encstr = encstr.substring(1);
}
// fill the result with blanks
char c;
for(int i=0; i<maxn; i++)
{
decstring[i] = ' ';
}
// insert the uppercase letters
for(int i=0; i<N; i++)
{
decstring[fibmap.get(fnums[i])-1] = uppercases[i];
}
// print the result
for(int i=0; i<maxn; i++)
{
System.out.print(decstring[i]);
}
System.out.println();
}
}
}