fork(1) download
  1. /* package codechef; // 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. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. try{
  14. int T = Integer.parseInt(reader.readLine());
  15. while(T!=0){
  16. int N = Integer.parseInt(reader.readLine());
  17. //String B = reader.readLine();
  18. StringTokenizer st = new StringTokenizer(reader.readLine());
  19. int[] A = new int[N];
  20. Queue<Integer> Q = new LinkedList<>();
  21. Queue<Integer> P = new LinkedList<>();
  22. for(int i=0;i<N;i++){
  23.  
  24.  
  25. A[i] = Integer.parseInt(st.nextToken());
  26. if(A[i] % 2 == 0){
  27. Q.add(A[i]);
  28. }
  29. else
  30. P.add(A[i]);
  31.  
  32.  
  33. }
  34. //int count=0;
  35. // for(int k=0;k<N;k++){
  36. // if(A[k] % 2 == 0){
  37. // System.out.print(A[k]+" ");
  38. // }
  39.  
  40.  
  41. for(int i=0;i<Q.size();i++){
  42.  
  43. int curr = Q.poll();
  44. System.out.print(curr+" ");
  45.  
  46. }
  47.  
  48. for(int i=0;i<P.size();i++){
  49.  
  50. int curr = P.poll();
  51. System.out.print(curr+" ");
  52.  
  53. }
  54.  
  55. System.out.println("/n");
  56. // for(int i=0;i<count;i++){
  57. // for(int j=1;j<N;j++){
  58. // if(A[j] % 2 == 0){
  59. // int temp = A[i];
  60. // A[i] = A[j];
  61. // A[j] = temp;
  62. // break;
  63. // }
  64. // }
  65. // }
  66. // for(int i=0;i<N;i++){
  67. // System.out.print(A[i]);
  68. // }
  69. T--;
  70. }
  71. }
  72. catch(Exception e){
  73. e.printStackTrace();
  74. }
  75. }
  76. }
  77.  
Success #stdin #stdout #stderr 0.06s 49152KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
java.lang.NumberFormatException: null
	at java.base/java.lang.Integer.parseInt(Integer.java:620)
	at java.base/java.lang.Integer.parseInt(Integer.java:776)
	at Ideone.main(Main.java:15)