Advertisement
Guest User

Untitled

a guest
Aug 28th, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. package CardapiodaSraMontagny;
  2.  
  3. import java.util.HashSet;
  4. import java.util.Scanner;
  5. import java.util.Set;
  6.  
  7. public class Main {
  8.    
  9.     public static void main(String[] args) {
  10.        
  11.         int numPessoas = 0;
  12.         Scanner input = new Scanner(System.in);
  13.  
  14.         Set<String> pratosSelecionado = new HashSet<String>();
  15.         Set<String> pratosVetado = new HashSet<String>();
  16.        
  17.         while (input.hasNextLine()) {
  18.            
  19.             numPessoas = input.nextInt();
  20.            
  21.             for(int x = 0; x < numPessoas; x++) {
  22.                
  23.                 String escolha1 = input.next();
  24.                
  25.                 if (escolha1.charAt(0) == '!' ) {
  26.                     pratosVetado.add(escolha1.substring(1));
  27.                 } else {
  28.                     pratosSelecionado.add(escolha1);
  29.                 }
  30.                
  31.                 String escolha2 = input.next();
  32.                
  33.                 if (escolha2.charAt(0) == '!' ) {
  34.                     pratosVetado.add(escolha2.substring(1));
  35.                 } else {
  36.                     pratosSelecionado.add(escolha2);
  37.                 }          
  38.             }      
  39.            
  40.             // Verifica se algum prato no pratosSelecionado nao esta no pratosVetado
  41.             String resp = "nao";
  42.                    
  43.             for (String psel : pratosSelecionado ) {
  44.                 if (!pratosVetado.contains(psel) ) {
  45.                     resp = "sim";
  46.                     break;
  47.                 }
  48.             }
  49.            
  50.             System.out.println(resp);
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement