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();
- evaluatePrefixes(prefixProp, IdOfCom);
- }
- }
- System.out.println(prefixUnique.size());
- for (int i = 0; i < prefixUnique.size(); i++) {
- System.out.println(prefixUnique.get(i) + " " + IDforProposal[i] + " " + countOfID[i]);
- }
- }
- public static int indexOfExistingPrefix(String prefixProp) {
- if (prefixUnique.isEmpty()) {
- return -1;
- } else {
- for (String s : prefixUnique) {
- if (s.equals(prefixProp)) {
- return prefixUnique.indexOf(s);
- }
- }
- }
- return -1;
- }
- public static void evaluatePrefixes(String prefixProp, Integer IdOfCom) {
- int prefixIndex = indexOfExistingPrefix(prefixProp);
- int indexOfPrefixProp;
- int indexOfHigherPrefix;
- //pro navrzeny prefix musime zkontrolovat, zda neni jiz soucasti higher prefixu, pokud ano, navysime higher
- for (String s : prefixUnique) {
- if (s.startsWith(prefixProp)) {
- indexOfHigherPrefix = prefixUnique.indexOf(s);
- countOfID[indexOfHigherPrefix]++;
- }
- }
- if (prefixIndex < 0) //novy nalez prefixu, pridame do unikatnich, pridame mu hlasovani a kdo hlasoval
- {
- prefixUnique.add(prefixProp);
- indexOfPrefixProp = prefixUnique.indexOf(prefixProp);
- IDforProposal[indexOfPrefixProp] += " " + IdOfCom + " ";
- // countOfID[indexOfPrefixProp]++;
- } else //jiz nalezen, nepridavame, musime kontrolovat, kdo hlasoval, nehlasujeme, nejde startswith
- {
- indexOfPrefixProp = prefixUnique.indexOf(prefixProp);
- IDforProposal[indexOfPrefixProp] += IdOfCom + " ";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement