Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

RE了上万次了,请高手指教一下java写的。。谢谢。。。

Posted by jucai at 2007-03-31 21:29:21 on Problem 1026
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator