Advertisement
MonsterScripter

CodinGame_2023_09_02__10_26_00__reverse_words.java

Sep 2nd, 2023
943
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.math.*;
  4.  
  5. /**
  6.  * Objectif
  7.  *
  8.  * Inverser l'ordre des mots dans une phrase donnée.
  9.  *
  10.  * Entrée
  11.  * Ligne 1 : Une phrase s.
  12.  *
  13.  * Sortie
  14.  * Une phrase avec les mots dans l'ordre inverse.
  15.  *
  16.  * Contraintes
  17.  * Aucune.
  18.  *
  19.  * Exemple
  20.  * Test 1
  21.  * Entrée
  22.  * Hello there!!
  23.  *
  24.  * Sortie attendue
  25.  * there!! Hello
  26.  *
  27.  * Test 2
  28.  * Entrée
  29.  * We had a three-course meal.
  30.  *
  31.  * Sortie attendue
  32.  * meal. three-course a had We
  33.  *
  34.  * Test 3
  35.  * Entrée
  36.  * Oh, how I'd love to go!
  37.  *
  38.  * Sortie attendue
  39.  * go! to love I'd how Oh,
  40.  *
  41.  * Test 4
  42.  * Entrée
  43.  * Reaching the large house near the Horse Guards' barracks, in which Anatole lived, Pierre entered the lighted porch, ascended the stairs, and went in at the open door.
  44.  *
  45.  * Sortie attendue
  46.  * door. open the at in went and stairs, the ascended porch, lighted the entered Pierre lived, Anatole which in, barracks, Guards' Horse the near house large the Reaching
  47.  */
  48. class Solution {
  49.  
  50.     public static void main(String args[]) {
  51.         Scanner in = new Scanner(System.in);
  52.         String s = in.nextLine();
  53.         String[] t = s.split(" ");
  54.         System.out.print(t[t.length-1]);
  55.         for (int i=t.length-2; i >= 0; i--) {
  56.            System.out.print(" " + t[i]);
  57.         }
  58.         System.out.println();
  59.     }
  60. }
  61.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement