ورود

View Full Version : مبتدی: توضیح این کد



alirezafc
شنبه 22 آذر 1393, 14:48 عصر
[*=left]​import java.util.*;import java.io.*;


public class B {
Scanner sc;
PrintStream ps;

public void doIt() throws Exception
{
sc = new Scanner(new File("B.in"));
ps = new PrintStream(new File("B.out"));

int n = Integer.parseInt(sc.nextLine().trim());

for(int test=1;test<=n;test++)
{
String s = sc.nextLine();
String code = sc.nextLine();

char cs[] = new char[s.length()];
char codes[] = code.toCharArray();

for(int i=0;i<cs.length;i++)
{
char c = s.charAt(i);
if(c==' ')
{
cs[i] = ' ';
}
else
{
int ind = c - 'A';
cs[i] = codes[ind];
}
}

String out = new String(cs);

ps.printf("%d %s", test, out);
ps.println();

}
}

public static void main(String args[]) throws Exception
{
(new B()).doIt();
}

}