Advertisement
Alisator

PAL5_nedopsane-28-11

Nov 28th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.88 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.         for (int i = 0; i < countMembers; i++) {
  38.             IdOfCom = new Integer(i);
  39.             countOfProp = Integer.parseInt(br.readLine());
  40.             for (int j = 0; j < countOfProp; j++) {
  41.                 prefixProp = br.readLine();
  42.                 evaluatePrefixesByComitteVotes(prefixProp, IdOfCom);
  43.             }
  44.         }
  45.     }
  46.  
  47.     public static void evaluatePrefixesByComitteVotes(String prefix, int IdOfCom) {
  48.         int indexOfUniquePrefix;
  49.         int indexOfHigherPrefix;
  50.         if (prefix.isEmpty()) {
  51.  
  52.         } else {
  53.             for (String s : prefixUnique) {
  54.                 if (s.startsWith(prefix)) { //zacinaji stejnym pefixem
  55.                     if (s.equals(prefix)) { //a jsou shodne - nepridavame do unique, jen zapocteme bod ke slovu s prefixem, musime kontrolovat porotce
  56.                         indexOfUniquePrefix = prefixUnique.indexOf(prefix);
  57.                         //pokud clen jeste nehlasoval, pridame ho
  58.                         if (!IDforProposal[indexOfUniquePrefix].contains(" " + IdOfCom + " "));
  59.                         {
  60.                             countOfID[indexOfUniquePrefix]++;
  61.                             IDforProposal[indexOfUniquePrefix] += IdOfCom + " ";
  62.                         }
  63.                         // else{ cotinue;}
  64.  
  65.                     } else { //nejsou shodne - pridame do unique, nema smysl kontrolovat porotce
  66.                         //vytvarime novy ale musime prict i k delsimu
  67.                         prefixUnique.add(prefix);
  68.                         indexOfUniquePrefix = prefixUnique.indexOf(prefix);
  69.                         countOfID[indexOfUniquePrefix]++;
  70.                         //pridamave poprve mezery z obou stran, pak uz jen za
  71.                         IDforProposal[indexOfUniquePrefix] = " " + IdOfCom + " ";
  72.                        
  73.                         indexOfHigherPrefix = prefixUnique.indexOf(prefix);
  74.                         countOfID[indexOfHigherPrefix]++;
  75.                         //pridamave poprve mezery z obou stran, pak uz jen za
  76.                         IDforProposal[indexOfHigherPrefix] = " " + IdOfCom + " ";
  77.  
  78.  
  79.                     }
  80.                 } //nezcinaji stejnym prefixem a nejsou tedy ani shodne - pridame do unique, nema smysl kontrolovat porotce
  81.                 else {
  82.                     prefixUnique.add(prefix);
  83.                     indexOfUniquePrefix = prefixUnique.indexOf(prefix);
  84.                     countOfID[indexOfUniquePrefix]++;
  85.                     //pridamave poprve mezery z obou stran, pak uz jen za
  86.                     IDforProposal[indexOfUniquePrefix] = " " + IdOfCom + " ";
  87.                 }
  88.             }
  89.         }
  90.  
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement