Pages

Monday 17 December 2012

UVA - 11286 - Conformity

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuffer sb = new StringBuffer("");
        while(true){
            int n=Integer.parseInt(br.readLine());
            if(n==0){
                break;
            }
            HashMap<String,Integer> hm=new HashMap<String, Integer>();
            int max=Integer.MIN_VALUE;
            int counterMax=0;
            for(int i=0;i<n;i++){
                StringTokenizer st=new StringTokenizer(br.readLine());
                int[] arr=new int[5];
                for(int j=0;j<5;j++){
                    arr[j]=Integer.parseInt(st.nextToken());
                }
                Arrays.sort(arr);
                StringBuilder str=new  StringBuilder("");
                for(int j=0;j<5;j++){
                    if(j>0)
                        str.append(" ");
                    str.append(arr[j]);
                }
                String temp=str.toString();
                if(hm.containsKey(temp)){
                    int index=hm.get(temp);
                    hm.put(temp, index+1);
                    if(index+1>max){
                        max=index+1;
                        counterMax=max;
                    }
                    else if(index+1==max){
                        counterMax+=max;
                    }
                }else{
                    hm.put(temp, 1);
                    if(1>max){
                        max=1;
                        counterMax=1;
                    }
                    else if(max==1){
                        counterMax++;
                    }
                }
            }
            sb.append(counterMax).append("\n");
        }
        System.out.print(sb);
    }
}

No comments:

Post a Comment