Advertisement
Ruhan_DIU

Card Trick-SnackDown 2019 1A

Oct 20th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.Scanner;
  4.  
  5.  
  6. public class Main {
  7.  
  8. public static void main(String[] args) {
  9. Scanner in = new Scanner(System.in);
  10.  
  11. int x=in.nextInt();
  12. for (int t = 0; t <x ; t++) {
  13. int d=in.nextInt();
  14. int[] num=new int[d];
  15. int[] cool=new int[d];
  16. int[] jerox=new int[d];
  17. for (int i = 0; i <d ; i++) {
  18. num[i]=in.nextInt();
  19. cool[i]=num[i];
  20. jerox[i]=num[i];
  21. }
  22. Arrays.sort(cool);
  23. boolean b=false;
  24. for (int i = 0; i <(num.length)-1 ; i++) {
  25.  
  26. for (int j = 0; j <d ; j++) {
  27. num[j]=jerox[j];
  28. }
  29.  
  30. int[] temp=new int[num.length];
  31. int k=-1;
  32. for (int j = 0; j <=i ; j++) {
  33. k++;
  34. temp[k]=num[j];
  35. num[j]=0;
  36. }
  37. int count=0;
  38. for(int a:temp){
  39. if(a!=0){
  40. count++;
  41. }
  42. }
  43.  
  44. k=-1;
  45. for (int j = 0; j <num.length; j++) {
  46. if(j<(num.length)-count){
  47. num[j]=num[j+count];
  48. }else {
  49. k++;
  50. num[j]=temp[k];
  51. }
  52. }
  53. Arrays.fill(temp,0);
  54. if(Arrays.equals(cool,num)){
  55. b=true;
  56. break;
  57. }
  58. // for(int s:num){
  59. // System.out.print(s+" ");
  60. // }
  61. // System.out.println();
  62.  
  63. }
  64.  
  65. if(b==true){
  66. System.out.println("YES");
  67.  
  68. }else{
  69. System.out.println("NO");
  70. }
  71.  
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement