| ||||||||||
| 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 | |||||||||
Carefully read F.A.QsIn Reply To:A runtime error Posted by:neramirez at 2008-07-28 00:56:35 > I write this code in Java but i get runtime error, waths wrong
>
> import java.io.BufferedReader;
> import java.io.IOException;
> import java.io.InputStreamReader;
> import java.util.ArrayList;
> import java.util.Collections;
>
>
> public class Main {
> static class Telefono implements Comparable<Telefono> {
> int reps = 1, number;
>
> public Telefono(int a) {
> this.number = a;
> }
>
> public int compareTo(Telefono obj) {
> return this.number - obj.number;
> }
>
> @Override
> public boolean equals(Object arg0) {
>
> return ((Telefono) (arg0)).number == this.number;
> }
>
> }
>
> static int pFormat(String a) {
> a = a.replaceAll(" ", "").replaceAll("-", "");
> a = a.replaceAll("[ABC]", "2");
> a = a.replaceAll("[DEF]", "3");
> a = a.replaceAll("[GHI]", "4");
> a = a.replaceAll("[JKL]", "5");
> a = a.replaceAll("[MNO]", "6");
> a = a.replaceAll("[PRS]", "7");
> a = a.replaceAll("[TUV]", "8");
> a = a.replaceAll("[WXY]", "9");
> return Integer.parseInt(a);
> }
>
> public static void main(String[] args) throws IOException {
> BufferedReader lc = new BufferedReader(new InputStreamReader(System.in));
> ArrayList<Telefono> tels = new ArrayList<Telefono>(100000);
> for (int i = Integer.parseInt(lc.readLine()); i > 0; i--) {
> String line = lc.readLine();
> Telefono tep = new Telefono(pFormat(line));
> int num = tels.indexOf(tep);
> if (num!=-1)
> tels.get(num).reps++;
> else tels.add(tep);
> }
>
> Collections.sort(tels);
> boolean dupl=false;
> for (Telefono telefono : tels) {
>
> if(telefono.reps>1){
> System.out.println((telefono.number/10000)+"-"+((String)(telefono.number+"")).substring(3)+" "+telefono.reps);
> dupl=true;
> }
>
> }
> if (!dupl)
> System.out.println("No duplicates.");
> }
> }
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator