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

Jave 的代码好长啊,我打字都这么慢,还是不要用好了

Posted by mathzqy at 2004-10-25 19:44:53 on Problem 1107
In Reply To:AC的代码,与喜欢java的朋友一起切磋! Posted by:Jin_j_y at 2004-10-25 11:49:10
> /*******************************************************************
> *AC的代码,与喜欢java的朋友一起切磋!
> *开始的时候RE了,我想不通是什么原因:不可能是越界,也不可能是IOException。
> *后来judge说可能是nullPointerException,但我还是觉得不可能,
> *于是继续研究题目原文,忽然发现:如果密文中没有a,会怎么办?
> *RE的原因:除数为0!
> ********************************************************************/
> import java.io.*;
> import java.util.*;
> 
> public class Main
> {
> 	public static void main(String[] args)throws Exception
> 	{
> 		char [] kc1=new char[85];
> 		int  [] ka1=new int[85];
> 		char [] kc2=new char[85];
> 		int  [] ka2=new int[85];
> 		char [] kc3=new char[85];
> 		int  [] ka3=new int[85];
> 		int  k1,k2,k3;
> 		int  num1,num2,num3;
> 		int  i,j;
> 
> 		BufferedReader cin=new BufferedReader(new
>                                   InputStreamReader(System.in));
> 		String strnum;
> 		StringTokenizer strtok;
> 		//Read in the k1,k2,k3;
> 		strnum=cin.readLine();
> 		strtok=new StringTokenizer(strnum);
> 		k1=Integer.parseInt(strtok.nextToken());
> 		k2=Integer.parseInt(strtok.nextToken());
> 		k3=Integer.parseInt(strtok.nextToken());
> 		
> 		while(!(k1==0&&k2==0&&k3==0)){
> 			//Read in the encryption
> 			String str=cin.readLine();
> 			int size=str.length();
> 			num1=num2=num3=0;
> 			char ct;
> 			int at;
> 			//Analyse the encryption string
> 			for(i=0;i<size;++i)
> 			{  ct=str.charAt(i);			
> 			   if(ct=='_')at=2;
> 			   else at=(ct-'a')/9;
> 				switch(at){
> 					case 0:ka1[num1]=i;kc1[num1]=ct;num1++;break;
> 					case 1:ka2[num2]=i;kc2[num2]=ct;num2++;break;
> 					case 2:ka3[num3]=i;kc3[num3]=ct;num3++;break;
> 				}
> 			}
> 			//Rotation
> 			/**********************************************************
> 			*RE就在这里!!
> 			*Maybe there is no letter among the group 1, then num1=0
> 			**********************************************************/
> 			if(num1!=0)k1=k1%num1;
> 			if(num2!=0)k2=k2%num2;
> 			if(num3!=0)k3=k3%num3;
> 			
> 			if(k1!=0&&num1!=0){
> 				char [] okc1=new char[num1];
> 				System.arraycopy(kc1,0,okc1,0,num1);
> 				for(i=0;i<num1;++i){
> 					j=i+k1;
> 					if(j>=num1)j-=num1;
> 					kc1[j]=okc1[i];
> 				}
> 			}
> 
> 			if(k2!=0&&num2!=0){
> 				char [] okc2=new char[num2];
> 				System.arraycopy(kc2,0,okc2,0,num2);
> 				for(i=0;i<num2;++i){
> 					j=i+k2;
> 					if(j>=num2)j-=num2;
> 					kc2[j]=okc2[i];
> 				}
> 			}
> 
> 			if(k3!=0&&num3!=0){
> 				char [] okc3=new char[num3];
> 				System.arraycopy(kc3,0,okc3,0,num3);
> 				for(i=0;i<num3;++i){
> 					j=i+k3;
> 					if(j>=num3)j-=num3;
> 					kc3[j]=okc3[i];
> 				}
> 			}
> 			//Decryption string
> 			char[] sstr=new char[size];
> 			for(i=0;i<num1;++i)
> 				sstr[ka1[i]]=kc1[i];
> 			for(i=0;i<num2;++i)
> 				sstr[ka2[i]]=kc2[i];
> 			for(i=0;i<num3;++i)
> 				sstr[ka3[i]]=kc3[i];
> 			//Output the decryption string
> 			System.out.println(sstr);
> 
> 			//Handle the new case
> 			strnum=cin.readLine();
> 			strtok=new StringTokenizer(strnum);
> 			k1=Integer.parseInt(strtok.nextToken());
> 			k2=Integer.parseInt(strtok.nextToken());
> 			k3=Integer.parseInt(strtok.nextToken());
> 		}
> 	}
> }
> 

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