Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.58 KB | None | 0 0
  1. package G;
  2.  
  3. import java.io.IOException;
  4. import java.util.Scanner;
  5.  
  6. /**
  7.  * IMPORTANT: O nome da classe deve ser "Main" para que a sua solução execute
  8.  * Class name must be "Main" for your solution to execute El nombre de la clase
  9.  * debe ser "Main" para que su solución ejecutar
  10.  */
  11. public class Main {
  12.  
  13.     public static boolean contains(int v[], int size, int value) {
  14.         for(int i=0; i<size; i++) {
  15.             if(v[i] == value) return true;
  16.         }
  17.         return false;
  18.     }
  19.    
  20.     public static void main(String[] args) throws IOException {
  21.        
  22.         Scanner s = new Scanner(System.in);
  23.         int t = s.nextInt();
  24.        
  25.         //
  26.         int size = 0;
  27.         int in[] = new int[11];
  28.         int out[] = new int[11];
  29.        
  30.         //
  31.         scope: for (int i = 0; i < t; i++) {
  32.            
  33.             //
  34.             int n = s.nextInt();
  35.            
  36.             // Prepare first element
  37.             int first = s.nextInt();
  38.             if(first > 5) {
  39.                 System.out.println("Ho Ho Ho!");
  40.                 continue;
  41.             }
  42.             size = 2;
  43.             in[0] = first;
  44.             in[1] = -first;
  45.            
  46.             //
  47.             for(int j=1; j<n; j++) {
  48.                 int current = s.nextInt();
  49.                
  50.                 for(int k=0; k<size; k++)
  51.                     out[k] = in[k];
  52.                
  53.                 int newSize = 0;
  54.                 for(int k=0; k<size; k++) {
  55.                     if(Math.abs(out[k] + current) <= 5 && !contains(in, newSize, out[k] + current))
  56.                         in[newSize++] = out[k] + current;
  57.                     if(Math.abs(out[k] - current) <= 5 && !contains(in, newSize, out[k] - current))
  58.                         in[newSize++] = out[k] - current;
  59.                 }
  60.                
  61.                 if(newSize == 0) {
  62.                     System.out.println("Ho Ho Ho!");
  63.                     continue scope;
  64.                 }
  65.                
  66.                 size = newSize;
  67.             }
  68.            
  69.             System.out.println("Feliz Natal!");
  70.         }
  71.     }
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement