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:1002超时~~~~java做的哪位高手能帮忙看下啊~~

Posted by D00109 at 2008-04-04 14:38:54 on Problem 1002
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:
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