fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. static String reverse(String str,int[] sum)
  11. {
  12. char[] s = str.toCharArray();
  13. int n = s.length;
  14. int halfLength = n / 2;
  15. for (int i=0; i<halfLength; i++)
  16. {
  17. if(sum[i]%2==1)
  18. {
  19. char temp = s[i];
  20. s[i] = s[n-1-i];
  21. s[n-1-i] = temp;
  22. }
  23.  
  24. }
  25. return new String(s);
  26. }
  27. public static void main (String[] args) throws java.lang.Exception
  28. {
  29. // your code goes here
  30. Scanner sc=new Scanner(System.in);
  31. String s=sc.next();
  32. int m=sc.nextInt();
  33. int n=s.length();
  34. int[] sum=new int[n/2];
  35.  
  36.  
  37. for(int i=0;i<m;i++)
  38. {
  39. int x=sc.nextInt()-1;
  40. int r=n-x;
  41.  
  42. for(int j=x;j<Math.min(n-1,r);j++)
  43. sum[j]++;
  44. }
  45.  
  46. String res=reverse(s,sum);
  47. System.out.println(res);
  48. }
  49. }
Runtime error #stdin #stdout #stderr 0.09s 2184192KB
stdin
abcdef
1
2
stdout
Standard output is empty
stderr
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
	at Ideone.main(Main.java:43)