Advertisement
Alisator

PAL5_nedopsane_29-11

Nov 29th, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.28 KB | None | 0 0
  1. package pal;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.ArrayList;
  7.  
  8. public class Main {
  9.  
  10.     static public final int MAX_PROPOSAL = 100000;
  11.     static public String alphabet; // chars in alphabet
  12.     static public int countMembers; //count of comittee memebers
  13.     static public int countMembersAccept; // count of comittee memebers for acceptance of proposal
  14.     static public int K; //
  15.     static public ArrayList<String> prefixUnique;
  16.     static public String[] IDforProposal;
  17.     static public int[] countOfID;
  18.     static public int maxProposal;
  19.  
  20.     public static void main(String[] args) throws IOException {
  21.  
  22.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  23.         String[] in = br.readLine().split(" ");
  24.         alphabet = in[0];
  25.         countMembers = Integer.parseInt(in[1]);
  26.         countMembersAccept = Integer.parseInt(in[2]);
  27.         K = Integer.parseInt(in[3]);
  28.  
  29.         prefixUnique = new ArrayList<>();
  30.         IDforProposal = new String[MAX_PROPOSAL];
  31.         countOfID = new int[MAX_PROPOSAL];
  32.  
  33.         int countOfProp;
  34.         String prefixProp;
  35.         Integer IdOfCom;
  36.         String IDsOfcomittee;
  37.  
  38.         for (int i = 0; i < countMembers; i++) {
  39.             IdOfCom = new Integer(i);
  40.             countOfProp = Integer.parseInt(br.readLine());
  41.             for (int j = 0; j < countOfProp; j++) {
  42.                 prefixProp = br.readLine();
  43.                 evaluatePrefixes(prefixProp, IdOfCom);
  44.  
  45.             }
  46.         }
  47.         System.out.println(prefixUnique.size());
  48.         for (int i = 0; i < prefixUnique.size(); i++) {
  49.             System.out.println(prefixUnique.get(i) + " " + IDforProposal[i] + " " + countOfID[i]);
  50.         }
  51.     }
  52.  
  53.     public static int indexOfExistingPrefix(String prefixProp) {
  54.         if (prefixUnique.isEmpty()) {
  55.             return -1;
  56.         } else {
  57.             for (String s : prefixUnique) {
  58.                 if (s.equals(prefixProp)) {
  59.                     return prefixUnique.indexOf(s);
  60.                 }
  61.             }
  62.         }
  63.         return -1;
  64.     }
  65.  
  66.     public static void evaluatePrefixes(String prefixProp, Integer IdOfCom) {
  67.         int prefixIndex = indexOfExistingPrefix(prefixProp);
  68.         int indexOfPrefixProp;
  69.         int indexOfHigherPrefix;
  70.         //pro navrzeny prefix musime zkontrolovat, zda neni jiz soucasti higher prefixu, pokud ano, navysime higher
  71.         for (String s : prefixUnique) {
  72.             if (s.startsWith(prefixProp)) {
  73.                 indexOfHigherPrefix = prefixUnique.indexOf(s);
  74.                 countOfID[indexOfHigherPrefix]++;
  75.             }
  76.         }
  77.  
  78.         if (prefixIndex < 0) //novy nalez prefixu, pridame do unikatnich, pridame mu hlasovani a kdo hlasoval
  79.         {
  80.             prefixUnique.add(prefixProp);
  81.             indexOfPrefixProp = prefixUnique.indexOf(prefixProp);
  82.             IDforProposal[indexOfPrefixProp] += " " + IdOfCom + " ";
  83.             //   countOfID[indexOfPrefixProp]++;
  84.         } else //jiz nalezen, nepridavame, musime kontrolovat, kdo hlasoval, nehlasujeme, nejde startswith
  85.         {
  86.             indexOfPrefixProp = prefixUnique.indexOf(prefixProp);
  87.             IDforProposal[indexOfPrefixProp] += IdOfCom + " ";
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement