Advertisement
MonsterScripter

CodinGame_2023_09_02__09_50_47__reverse_digit_max.cpp

Sep 2nd, 2023
1,106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. /**
  4.  * Objectif
  5.  *
  6.  * Étant donné n entiers dans un tableau a, inverser les chiffres de chaque entier dans le tableau. Ensuite, calculer la valeur absolue de chaque entier et afficher la valeur la plus élevée.
  7.  *
  8.  * Entrée
  9.  * Ligne 1 : n, le nombre d'entiers à fournir
  10.  * Ligne 2 : a, le tableau d'entiers
  11.  *
  12.  * Sortie
  13.  * Ligne 1 : Le plus grand des nombres inversés dans le tableau
  14.  *
  15.  * Contraintes
  16.  * 0 < n < 10
  17.  *
  18.  * Exemple
  19.  * Entrée
  20.  * 2
  21.  * 21 -94
  22.  *
  23.  * Sortie
  24.  * 49
  25.  */
  26. class Solution {
  27.  
  28.     public static void main(String args[]) {
  29.         Scanner in = new Scanner(System.in);
  30.         int n = in.nextInt();
  31.         if (in.hasNextLine()) {
  32.             in.nextLine();
  33.         }
  34.         String a = in.nextLine();
  35.         String[] b = a.split(" ");
  36.         int max = 0;
  37.         for (String s : b) {
  38.             // Vérifier si c'est un nombre entier
  39.             if (s.matches("(-?[0-9]+)")) {
  40.                 s = s.replace("-", ""); // Supprimer le signe négatif pour obtenir la valeur absolue
  41.                 int x = Integer.parseInt(new StringBuilder(s).reverse().toString()); // Inverser les chiffres et convertir en entier
  42.                 if (max < x)
  43.                     max = x; // Mettre à jour la valeur maximale si nécessaire
  44.             }
  45.         }
  46.         System.out.println(max); // Afficher le résultat
  47.     }
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement