Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Test{
- static Scanner sc = new Scanner(System.in);
- public static void main(String[] args) {
- int n = sc.nextInt();
- String s = sc.next();
- helpMochaToSort(n, s);
- }
- public static void helpMochaToSort(int n, String s) {
- ArrayList<Integer> res = new ArrayList<Integer>();
- char[] temp = s.toCharArray();
- Arrays.sort(temp);
- for(int i=0; i < n; i++){
- if(s.charAt(i) != temp[i])
- res.add(i);
- }
- if(res.isEmpty()){
- System.out.println(0);
- return;
- }
- System.out.println(1);
- System.out.print(res.size() + " ");
- for(int a : res)
- System.out.print(a + " ");
- System.out.println();
- }
- }
Add Comment
Please, Sign In to add comment