Advertisement
Guest User

Untitled

a guest
Apr 15th, 2021
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. package com.telerikacademy;
  2.  
  3. import java.util.*;
  4. import java.util.stream.Stream;
  5.  
  6. public class Main {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.         int i = scanner.nextInt();
  10.         scanner.nextLine();
  11.  
  12.         // Declaring input and output strings, as well as operational integer arrays:
  13.         String res = "";
  14.         String s;
  15.         int[] sArr;
  16.         int[] sArrSorted;
  17.  
  18.         for (int k = 0; k < i; k++) {
  19.             // Getting string input, splitting it by "," and
  20.             // parsing the resulting string elements to integer and assigning them to the int array
  21.             s = scanner.nextLine();
  22.             sArr = Stream.of(s.split(",")).mapToInt(Integer::parseInt).toArray();
  23.  
  24.             // Cloning the integer array and sorting the clone:
  25.             sArrSorted = sArr.clone();
  26.             Arrays.sort(sArrSorted);
  27.  
  28.             // Comparing the original and sorted arrays and assigning the respective output:
  29.             res += (Arrays.equals(sArr, sArrSorted)) ? "true," : "false,";
  30.         }
  31.  
  32.         // Cutting out the last "," and replacing the rest with a newline to print the output in the requested format:
  33.         System.out.print(res.substring(0, res.length() - 1).replace(",", "\n"));
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement