Advertisement
roronoa

carrés parfaits, appartenance ou pas à un tab

Apr 24th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.math.*;
  4. class Solution {
  5.  
  6.     public static void main(String args[])
  7.     {
  8.         Scanner in = new Scanner(System.in);
  9.         int m = in.nextInt();
  10.         if (in.hasNextLine())
  11.             in.nextLine();
  12.         String i = in.nextLine();
  13.         String t[] = i.split(" ");
  14.         int s = t.length;
  15.         int u[] = new int[s];
  16.         for(int j=0;j<s;j++)
  17.         {
  18.             u[j]=Integer.parseInt(t[j]);  
  19.         }
  20.         String res = "";
  21.         for(int j = 1; j <= m; j++)
  22.         {
  23.             if(carreParfait(j) && !inTab(u,j))
  24.                 res += j + " ";
  25.         }
  26.         System.out.println(res.equals("")?"None":res.trim());
  27.     }
  28.     public static boolean carreParfait(int x)
  29.     {
  30.         boolean retour = false;
  31.         for(int i = 0; i <= x; i++)
  32.         {
  33.             if(i*i == x)
  34.                 retour = true;
  35.         }
  36.         return retour;
  37.     }
  38.     public static boolean inTab(int[] tab, int x)
  39.     {
  40.         boolean retour = false;
  41.         for(int i =0 ; i< tab.length; i++)
  42.         {
  43.             if(tab[i] == x)
  44.                 retour = true;
  45.         }
  46.         return retour;
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement