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

always runtime error

Posted by tfeng at 2013-02-03 08:11:59 on Problem 2092
本机数据没出问题,但提交总是runtime error。。。各位帮忙看看


import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;


public class Main {

    static class num implements Comparable{

        int name;
        int cnt;
        public int compareTo(Object o) {
            num b = (num)o;
            if(this.cnt == b.cnt) {
                return this.name - b.name;
            }
            else
                return this.cnt - b.cnt;
        }
    }

    public static class Comp implements Comparator<num> {

        public int compare(num a, num b) {
            if (a.cnt == b.cnt) {
                return a.name - b.name;
            } else {
                return a.cnt - b.cnt;
            }
            /*
             * if(a.cnt > b.cnt) return 1; else if(a.cnt < b.cnt) return -1;
             * else return 0;
             */
        }
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int N = in.nextInt();
            int M = in.nextInt();
            if (N == 0 && M == 0) {
                break;
            }
            int tmp = N * M;
            num[] tab = new num[10001];
            for (int i = 0; i <= 10000; i++) {
                tab[i] = new num();
                tab[i].name = i;
                tab[i].cnt = 0;
            }
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < M; j++) {
                    int A = in.nextInt();
                    //tab[A] = new num();
                    tab[A].name = A;
                    tab[A].cnt++;
                }

            }
          //  Comp c = new Comp();
            Arrays.sort(tab);
            //  for(int i = 10000; i >= 10000-tmp; i--)
            //    System.out.println("test name: "+ tab[i].name+" cnt: "+tab[i].cnt);
            // System.out.println(tab[0].name);
            int first_cnt = tab[10000].cnt;
            int first_index = 1;
            //System.out.println("test: "+tab[10000].name);
            for (int i = 10000; i >= (10000 - tmp + 1); i--) {
                if (tab[i].cnt == first_cnt) {
                    first_index = i;
                } else {
                    break;
                }
            }

            int sec_cnt = tab[first_index - 1].cnt;
            for (int i = (10000 - tmp + 1); i <= 10000; i++) {
                if (tab[i].cnt == sec_cnt) {
                    System.out.printf(tab[i].name + " ");
                } else {
                    continue;
                }
            }
            System.out.println();
            //System.out.println(tab[10000].name);
        }
    }
}

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