|
| 1 | +package programame; |
| 2 | + |
| 3 | +import java.util.HashSet; |
| 4 | +import java.util.Scanner; |
| 5 | +import java.util.Set; |
| 6 | + |
| 7 | + |
| 8 | +public class ProblemaG { |
| 9 | + |
| 10 | + public static Set<String> llegeixDesenvolupadors(Scanner sc) { |
| 11 | + //el conjunt de tecnologies que tenen els desenvolupadors |
| 12 | + Set<String> tecDes = new HashSet<>(); |
| 13 | + int D = sc.nextInt(); //llegeixo el nombre D de desenvolupadors |
| 14 | + sc.nextLine(); //netejo bufer després de llegir enter i abans del proper nextline |
| 15 | + |
| 16 | + //recorrem cada linia (cada linia es un desenvolupador |
| 17 | + //seguit d ls seves habilitats) |
| 18 | + for (int i = 0; i < D; ++i) { |
| 19 | + String linia = sc.nextLine(); |
| 20 | + String[] hd = linia.split(" "); //hd es habiliatt desenvolupador |
| 21 | + |
| 22 | + //afegim les habilitats del desenvolupador al set |
| 23 | + //(ens despreocupem dels duplicats, el set ja se n'encarrega que no |
| 24 | + //n'hi hagin) |
| 25 | + for (int j = 1; j < hd.length; ++j) |
| 26 | + tecDes.add(hd[j]); |
| 27 | + } |
| 28 | + return tecDes; |
| 29 | + |
| 30 | + } |
| 31 | + |
| 32 | + public static void llegeixProjectes(Scanner sc, Set<String> tecDes) { |
| 33 | + int P = sc.nextInt(); //llegeixo el nombre P de projectes |
| 34 | + sc.nextLine(); |
| 35 | + |
| 36 | + //RECORRO ELS PROJECTES |
| 37 | + for (int i = 0; i < P; ++i) { |
| 38 | + |
| 39 | + String linia = sc.nextLine(); |
| 40 | + String[] hrp = linia.split(" "); //hrp es habilitats requerida pel projecte |
| 41 | + |
| 42 | + //RECORRO LES HABILITATS REQUEREIDES PER CADA PROJECTE I SI ALGUN |
| 43 | + //PROJECTE VEIEM QUE ELS SEUS DESENVOLUPADORS FALLEN EN ALGUNA HAB |
| 44 | + //ILITAT PAREM I SORTIM DEL BUCLE SEGUENT: |
| 45 | + boolean projectePossible = true; |
| 46 | + for (int j = 1; j < hrp.length; ++j) { |
| 47 | + if(!(tecDes.contains(hrp[j]))) { |
| 48 | + System.out.println("IMPOSIBLE"); |
| 49 | + projectePossible = false; |
| 50 | + break; |
| 51 | + } |
| 52 | + } |
| 53 | + if (projectePossible) |
| 54 | + System.out.println("POSIBLE"); |
| 55 | + } |
| 56 | + } |
| 57 | + public static void main(String[] args) { |
| 58 | + Scanner sc = new Scanner(System.in); |
| 59 | + llegeixProjectes(sc, llegeixDesenvolupadors(sc)); |
| 60 | + } |
| 61 | +} |
0 commit comments