UVA 11063 Java

  1. import java.util.*;
  2.  
  3. public class main{
  4. public static void main(String[] args) {
  5. Scanner sc=new Scanner(System.in);
  6. int cases = 0;
  7. while(sc.hasNextInt())
  8. {
  9. int input = sc.nextInt();
  10. if(input >= 2 && input <= 100)
  11. {
  12. cases++;
  13. int[] datas = new int[input];
  14. List sum = new ArrayList();
  15. for(int i = 0; i < input; i++)
  16. datas[i] = sc.nextInt();
  17. boolean check = true;
  18. for(int i = 0; i < input; i++)
  19. for(int j = 0; j < input; j++)
  20. if(i <= j)
  21. {
  22. int temp = datas[i] + datas[j];
  23. if(sum.indexOf(temp) == -1)
  24. sum.add(temp);
  25. else
  26. {
  27. check = false;
  28. break;
  29. }
  30. }
  31. if(check)
  32. System.out.printf("Case #%d: It is a B2-Sequence.\r\n", cases);
  33. else
  34. System.out.printf("Case #%d: It is not a B2-Sequence.\r\n", cases);
  35. }
  36. }
  37. }
  38. };

留言

這個網誌中的熱門文章

C# 井字遊戲