UVA 10038 Java

  1. import static java.lang.System.*;
  2. public class main{
  3. public static void main(String[] args) {
  4. Scanner sc=new Scanner(System.in);
  5. while(sc.hasNextInt())
  6. {
  7. int size = sc.nextInt();
  8. boolean is_jolly = true;
  9. if(size != 1)
  10. {
  11. int[] input = new int[size];
  12. for(int i = 0; i < size; i++)
  13. input[i] = sc.nextInt();
  14. int[] dif = new int[size -1];
  15. for(int i = 0; i < size-1; i++)
  16. dif[i] = Math.abs(input[i+1] - input[i]);
  17. Arrays.sort(dif);
  18. for(int i = 0; i < size-1; i++)
  19. if(dif[i] != i+1)
  20. {
  21. is_jolly = false;
  22. break;
  23. }
  24. }
  25. else
  26. sc.nextInt();
  27. if(is_jolly)
  28. System.out.println("Jolly");
  29. else
  30. System.out.println("Not jolly");
  31. }
  32. }
  33. };

留言

這個網誌中的熱門文章

C# 井字遊戲