Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.telerikacademy;
- import java.util.*;
- import java.util.stream.Stream;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int i = scanner.nextInt();
- scanner.nextLine();
- // Declaring input and output strings, as well as operational integer arrays:
- String res = "";
- String s;
- int[] sArr;
- int[] sArrSorted;
- for (int k = 0; k < i; k++) {
- // Getting string input, splitting it by "," and
- // parsing the resulting string elements to integer and assigning them to the int array
- s = scanner.nextLine();
- sArr = Stream.of(s.split(",")).mapToInt(Integer::parseInt).toArray();
- // Cloning the integer array and sorting the clone:
- sArrSorted = sArr.clone();
- Arrays.sort(sArrSorted);
- // Comparing the original and sorted arrays and assigning the respective output:
- res += (Arrays.equals(sArr, sArrSorted)) ? "true," : "false,";
- }
- // Cutting out the last "," and replacing the rest with a newline to print the output in the requested format:
- System.out.print(res.substring(0, res.length() - 1).replace(",", "\n"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement