Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pal;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.ArrayList;
- public class Main {
- static public final int MAX_PROPOSAL = 100000;
- static public String alphabet; // chars in alphabet
- static public int countMembers; //count of comittee memebers
- static public int countMembersAccept; // count of comittee memebers for acceptance of proposal
- static public int K; //
- static public ArrayList<String> prefixUnique;
- static public String[] IDforProposal;
- static public int[] countOfID;
- static public int maxProposal;
- public static void main(String[] args) throws IOException {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- String[] in = br.readLine().split(" ");
- alphabet = in[0];
- countMembers = Integer.parseInt(in[1]);
- countMembersAccept = Integer.parseInt(in[2]);
- K = Integer.parseInt(in[3]);
- prefixUnique = new ArrayList<>();
- IDforProposal = new String[MAX_PROPOSAL];
- countOfID = new int[MAX_PROPOSAL];
- int countOfProp;
- String prefixProp;
- Integer IdOfCom;
- String IDsOfcomittee;
- for (int i = 0; i < countMembers; i++) {
- IdOfCom = new Integer(i);
- countOfProp = Integer.parseInt(br.readLine());
- for (int j = 0; j < countOfProp; j++) {
- prefixProp = br.readLine();
- evaluatePrefixesByComitteVotes(prefixProp, IdOfCom);
- }
- }
- }
- public static void evaluatePrefixesByComitteVotes(String prefix, int IdOfCom) {
- int indexOfUniquePrefix;
- int indexOfHigherPrefix;
- if (prefix.isEmpty()) {
- } else {
- for (String s : prefixUnique) {
- if (s.startsWith(prefix)) { //zacinaji stejnym pefixem
- if (s.equals(prefix)) { //a jsou shodne - nepridavame do unique, jen zapocteme bod ke slovu s prefixem, musime kontrolovat porotce
- indexOfUniquePrefix = prefixUnique.indexOf(prefix);
- //pokud clen jeste nehlasoval, pridame ho
- if (!IDforProposal[indexOfUniquePrefix].contains(" " + IdOfCom + " "));
- {
- countOfID[indexOfUniquePrefix]++;
- IDforProposal[indexOfUniquePrefix] += IdOfCom + " ";
- }
- // else{ cotinue;}
- } else { //nejsou shodne - pridame do unique, nema smysl kontrolovat porotce
- //vytvarime novy ale musime prict i k delsimu
- prefixUnique.add(prefix);
- indexOfUniquePrefix = prefixUnique.indexOf(prefix);
- countOfID[indexOfUniquePrefix]++;
- //pridamave poprve mezery z obou stran, pak uz jen za
- IDforProposal[indexOfUniquePrefix] = " " + IdOfCom + " ";
- indexOfHigherPrefix = prefixUnique.indexOf(prefix);
- countOfID[indexOfHigherPrefix]++;
- //pridamave poprve mezery z obou stran, pak uz jen za
- IDforProposal[indexOfHigherPrefix] = " " + IdOfCom + " ";
- }
- } //nezcinaji stejnym prefixem a nejsou tedy ani shodne - pridame do unique, nema smysl kontrolovat porotce
- else {
- prefixUnique.add(prefix);
- indexOfUniquePrefix = prefixUnique.indexOf(prefix);
- countOfID[indexOfUniquePrefix]++;
- //pridamave poprve mezery z obou stran, pak uz jen za
- IDforProposal[indexOfUniquePrefix] = " " + IdOfCom + " ";
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement