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 |
1002超时~~~~java做的哪位高手能帮忙看下啊~~import java.io.IOException; import java.util.*; public class Main{ public static void main(String[] args) throws IOException{ char p; char[] s = new char[100]; int n,i,j,count; int[] a = new int[100]; String[] name = new String[100]; Scanner in = new Scanner(System.in); n=in.nextInt(); for(i=0;i<n;i++) { name[i]=""; a[i]=1; } for(i=0;i<n;i++) { p='1'; count=0; while(p!='\n') { p=(char)System.in.read(); if(p=='0') { name[i]=name[i]+"0"; count++; } else if(p=='1') { name[i]=name[i]+"1"; count++; } else if(p=='A'||p=='B'||p=='C'||p=='2') { name[i]=name[i]+"2"; count++; } else if(p=='D'||p=='E'||p=='F'||p=='3') { name[i]=name[i]+"3"; count++; } else if(p=='G'||p=='H'||p=='I'||p=='4') { name[i]=name[i]+"4"; count++; } else if(p=='J'||p=='K'||p=='L'||p=='5') { name[i]=name[i]+"5"; count++; } else if(p=='M'||p=='N'||p=='O'||p=='6') { name[i]=name[i]+"6"; count++; } else if(p=='P'||p=='R'||p=='S'||p=='7') { name[i]=name[i]+"7"; count++; } else if(p=='T'||p=='U'||p=='V'||p=='8') { name[i]=name[i]+"8"; count++; } else if(p=='W'||p=='X'||p=='Y'||p=='9') { name[i]=name[i]+"9"; count++; } if(count==3) { name[i]=name[i]+"-"; count++; } } } for(i=0;i<n-1;i++) for(j=i+1;j<n;j++) { if(name[i].equals(name[j])) { a[i]+=1; name[j]="lau"; } } for(i=0;i<n;i++) { name[i]=name[i]+" "+a[i]; } count=0; for(j=0;j<n;j++) { p='z'; for(i=0;i<n;i++) { if(name[i].charAt(0)<p) { p=name[i].charAt(0); count=i; } } if(name[count].charAt(0)=='l'||name[count].charAt(name[count].length()-1)=='1') { name[count]="lau"; continue; } else { System.out.println(name[count]); name[count]="lau"; } } } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator