Advertisement
jsprieto10

Problema Z greedy

Dec 4th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. // OJO: Este archivo no pertenece a ningún paquete (package)
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. /**
  7.  * Calcula la cantidad y la suma de numeros pares en una lista de numeros
  8.  * @author Rodrigo Cardoso
  9.  */
  10. public class ProblemaZ_rc {
  11.    
  12.     public static int np;                                                               // No. de datos pares
  13.     public static int snp;                                                              // Suma de datos pares
  14.    
  15.     public static void main(String[] args) throws IOException {
  16.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  17.         String lineain,data[];
  18.  
  19.         while (true){                                                                   // Ciclo hasta que haya datos
  20.             lineain = br.readLine();
  21.             if (lineain.isEmpty()) return;
  22.             data = lineain.split(" ");
  23.            
  24.             np = 0;
  25.             snp = 0;
  26.            
  27.             for (int i=0; i!=data.length; i++){
  28.                 int z = Integer.parseInt(data[i]);
  29.                 if (z % 2 == 0){
  30.                     np++;
  31.                     snp += z;
  32.                 }
  33.             }
  34.            
  35.             System.out.println(np + " " + snp);
  36.         }
  37.     }
  38.        
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement