ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1880. Psych Up's Eigenvalues

Solving with Collections
Posted by ucb.churringo 27 Aug 2013 04:18

When I run this code I get the right answer, why do I fail test #2


import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class EJ1880 {

    /**
     * @param args
     * @throws FileNotFoundException
     */
    public static void main(String[] args) throws FileNotFoundException {
        // TODO Auto-generated method stub
        File Arc = new File("C:\\Documents and Settings\\Admin\\workspace\\ACM\\src\\timus\\datos.txt");
        Scanner in = new Scanner(Arc);
        //Scanner in = new Scanner(System.in);
        ArrayList<Integer> L1 = new ArrayList<Integer>();
        ArrayList<Integer> B1 = new ArrayList<Integer>();

        //Cargar elementos
        int a = in.nextInt();
        for (int aux = 0; aux < a; aux++)
            L1.add(in.nextInt());

        int b = in.nextInt();
        for (int aux = 0; aux < b; aux++)
            L1.add(in.nextInt());

        int c = in.nextInt();
        for (int aux = 0; aux < c; aux++)
            L1.add(in.nextInt());

        //Ordenar elementos
        Collections.sort(L1);

        //Buscar cantidad de elementos repetidos
        for (int i = 0; i < L1.size(); i++) {
            if ((Collections.frequency(L1, L1.get(i)) > 1)) {
                B1.add(i);
            }
        }

        System.out.println(L1.size() - B1.size());

    }

}
Re: Solving with Collections
Posted by nrl 4 Jul 2014 06:16
You are using frequency for occurrence greater than 1, why not use equal to 3 ?
Also B1 will contain repeated elements, instead try to use HashSet.