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:1002超时~~~~java做的哪位高手能帮忙看下啊~~In Reply To:1002超时~~~~java做的哪位高手能帮忙看下啊~~ Posted by:liuzb1987 at 2008-03-20 23:26:18 /** * * @author 刚铎 */ import java.io.*; import java.util.*; import java.math.*; public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner in=new Scanner(System.in) ; int N=Integer.parseInt(in.nextLine()); String[]read=new String[N]; for(int i=0;i<N;i++) { read[i]=in.nextLine(); read[i]=read[i].replaceAll("-",""); read[i]=read[i].replaceAll("[ABC]","2"); read[i]=read[i].replaceAll("[DEF]","3"); read[i]=read[i].replaceAll("[GHI]","4"); read[i]=read[i].replaceAll("[JKL]","5"); read[i]=read[i].replaceAll("[MNO]","6"); read[i]=read[i].replaceAll("[PRS]","7"); read[i]=read[i].replaceAll("[TUV]","8"); read[i]=read[i].replaceAll("[WXY]","9"); } Arrays.sort(read); int howMany=read.length; for(int i=1;i<read.length;i++) if(read[i].equals(read[i-1])) howMany--; String[] numberSet=new String [howMany]; numberSet[0]=read[0]; int curr=1; for(int i=1;i<read.length;i++) if(read[i].equals(read[i-1])) continue; else numberSet[curr++]=read[i]; int[] numberCount=new int[howMany]; for(int i=0;i<numberSet.length;i++) for(int j=0;j<read.length;j++) if(numberSet[i].equals(read[j])) numberCount[i]++; for(int i=0;i<numberSet.length;i++) if(numberCount[i]>1){ System.out.print(numberSet[i].substring(0,3)); System.out.print("-"); System.out.print(numberSet[i].substring(3,7)); System.out.println(" "+numberCount[i]); } } } 我也是用Java做的.但是用了代替的方法先处理了一下.本地通过,但是交上去说runtime error Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator