2017年8月12日 星期六

UVA10038:Jolly Jumpers

  1. import java.util.*;  
  2.   
  3. class main{  
  4. public static void main(String[] args){  
  5. Scanner sc = new Scanner(System.in);  
  6. while(sc.hasNext()){  
  7. int[] N = new int[sc.nextInt()];  
  8. for(int i =0;i<N.length;i++)  
  9.  N[i] = sc.nextInt();  
  10.  isJolly(N);  
  11. }  
  12. }  
  13. static void isJolly(int[] N){  
  14. int[] n = new int[ N.length-1];  
  15. int i = 0 , j = 1 ,m = 0;  
  16. while(j < N.length){  
  17. int en = Math.abs(N[i]-N[j]);  
  18. n[m] = en ;  
  19. if(N.length-1 < en ||en == 0){  
  20. System.out.println("Not jolly");  
  21. return;  
  22. }  
  23.   
  24. m++;  
  25. i = j++;  
  26. }  
  27. for(int h = 0;h < n.length ; h++){  
  28. for(int c = 0;c < n.length ; c++){  
  29. if(h==c) continue;  
  30. if(n[h]==n[c]){  
  31. System.out.println("Not jolly");  
  32. return;}  
  33. }  
  34. }  
  35.   
  36.   
  37. System.out.println("Jolly");  
  38. }  
  39.   
  40.   
  41.   UVA10038:Jolly JumpersUVA10038:Jolly Jumpers  

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。