| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
RE了上万次了,请高手指教一下java写的。。谢谢。。。
import java.util.*;
class Ciphers
{
static int [] squ;
static int n;
static char[] message,reslut;
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
n = cin.nextInt();
while (n != 0)
{
String s = cin.nextLine();
squ = new int [n];
for(int i = 0;i < n; i ++)
squ[i] = cin.nextInt();
s = cin.nextLine();
int times;
message = new char [n];
String str = cin.nextLine();
if(str.indexOf(' ') != -1)
times = Integer.parseInt(str.substring(0,str.indexOf(' ')));
else times = 0;
while(times != 0){
str = str.substring(str.indexOf(' ')+1,str.length());
for(int i = 0; i < n; i ++){
if(i < str.length())
message[i] = str.charAt(i);
else
message[i] = ' ';
}
reslut = new char [n];
recCipher(times,message,reslut);
if(times % 2 == 0)
reslut = message;
for(int i = 0; i < n; i ++)
System.out.print(reslut[i]);
System.out.println();
str = cin.nextLine();
if(str.indexOf(' ')!= -1)
times = Integer.parseInt(str.substring(0,str.indexOf(' ')));
else times = 0;
}
System.out.println();
n = cin.nextInt();
}
}
public static void recCipher(int times,char[] message,char[]reslut)
{
if(times == 0)
return;
else{
for(int i = 0; i < n; i ++)
reslut[squ[i] -1] = message[i];
recCipher(times-1,reslut,message);
}
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator