코드그라운드 1 숫자 골라내기

Jmnote (토론 | 기여)님의 2018년 8월 25일 (토) 23:02 판 (Jmnote님이 코드그라운드 1 숫자 골라내기 문서를 CR1 숫자 골라내기 문서로 이동했습니다)

Java

/*
You should use the statndard input/output
in order to receive a score properly.
Do not use file input and output
Please be very careful. 
*/
import java.util.Scanner;
import java.util.HashSet;
/*
   As the name of the class should be Solution , using Solution.java as the filename is recommended.
   In any case, you can execute your program by running 'java Solution' command.
 */
public class Solution {
	static int Answer;
	public static void main(String args[]) throws Exception	{
		/*
		   The method below means that the program will read from input.txt, instead of standard(keyboard) input.
		   To test your program, you may save input data in input.txt file,
		   and call below method to read from the file when using nextInt() method.
		   You may remove the comment symbols(//) in the below statement and use it.
		   But before submission, you must remove the freopen function or rewrite comment symbols(//).
		 */		
		/*
		   Make new scanner from standard input System.in, and read data.
		 */
		Scanner sc = new Scanner(System.in);
		//Scanner sc = new Scanner(new FileInputStream("input.txt"));

		int T = sc.nextInt();
		for(int test_case = 0; test_case < T; test_case++) {
			// Answer = 0;
			/////////////////////////////////////////////////////////////////////////////////////////////
			/*
			   Implement your algorithm here.
			   The answer to the case will be stored in variable Answer.
			 */
			/////////////////////////////////////////////////////////////////////////////////////////////
            int N = sc.nextInt();
            HashSet<Integer> set = new HashSet<Integer>();
            for(int i=0; i<N; i++) {
                int x = sc.nextInt();
                if(set.contains(x)) set.remove(x);
                else set.add(x);
            }
            Answer = -1;
            for(int i: set) {
               if( Answer == -1) Answer = i;
               else Answer = Answer^i;
            }
			// Print the answer to standard output(screen).
			System.out.println("Case #"+(test_case+1));
			System.out.println(Answer);
		}
	}
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}