UVA 11063 Java

import java.util.*;

public class main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int cases = 0;
    while(sc.hasNextInt())
    {
    	int input = sc.nextInt();
    	if(input >= 2 && input <= 100)
    	{
    		cases++;
    		int[] datas = new int[input];
    		List sum = new ArrayList();
    		for(int i = 0; i < input; i++)
    			datas[i] = sc.nextInt();
    		boolean check = true;
    		for(int i = 0; i < input; i++)
    			for(int j = 0; j < input; j++)
    				if(i <= j)
    				{
    					int temp = datas[i] + datas[j];
    					if(sum.indexOf(temp) == -1)
    						sum.add(temp);
    					else
    					{
    						check = false;
    						break;
    					}
    				}
    		if(check)
    			System.out.printf("Case #%d: It is a B2-Sequence.\r\n", cases);
    		else
    			System.out.printf("Case #%d: It is not a B2-Sequence.\r\n", cases);
    		
    	}
    }
  }
};

留言

這個網誌中的熱門文章

C# 井字遊戲