From 6cf8308610bbda771de83b5d09cf049db8e80b8a Mon Sep 17 00:00:00 2001 From: Denia Lomas <50151794+dennxa@users.noreply.github.com> Date: Fri, 4 Nov 2022 01:55:01 -0700 Subject: [PATCH] add file via upload --- solutions/d1000000-codeJam.java | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 solutions/d1000000-codeJam.java diff --git a/solutions/d1000000-codeJam.java b/solutions/d1000000-codeJam.java new file mode 100644 index 00000000..a4584fda --- /dev/null +++ b/solutions/d1000000-codeJam.java @@ -0,0 +1,50 @@ +import java.util.Scanner; +import java.util.ArrayList; +import java.util.Collections; + +class Solution { + public static void main(String args[]) { + Scanner sc = new Scanner(System.in); + //Dame # casos + int cases = sc.nextInt(); + sc.nextLine(); + + for(int a=1; a <= cases; a++){ + //Dame # dados + int n = sc.nextInt(); + int lineaPosible = n; + sc.nextLine(); + + //Dame # de lados + String s = sc.nextLine(); + String[] newStr = s.split("\\s+"); + + //Variables + int cont = 0; + int numNext = 1; + + //String pasa a un array + ArrayList lados = new ArrayList(); + + //Array de string pasa a Arraylist de int + for (int i = 0; i < newStr.length; i++) { + lados.add(Integer.parseInt(newStr[i])); + } + + //ordenar arraylist + Collections.sort(lados); + + //verificar numeros + for (int i = 0; i < lineaPosible; i++) { + int temp2 = lados.get(i); + if (numNext <= temp2) { + cont= cont+1; + numNext = numNext+1; + } + } + + System.out.println("Case #"+a+": "+cont); + } + } + +} \ No newline at end of file