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

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

1 개요

코딩그라운드 1 숫자 골라내기
코드그라운드 연습문제
순번 문제 C C++ C# Java Python
1페이지 e
1 코드그라운드 1 숫자 골라내기
2 코드그라운드 2 프로그래밍 경진대회
3 코드그라운드 3 시험 공부
4 코드그라운드 4 다트 게임
5 코드그라운드 5 이항계수의 합
6 코드그라운드 6 미궁 속의 방
7 코드그라운드 7 좋은 수
8 코드그라운드 8 블럭 없애기
9 코드그라운드 9 화학자의 문장
10 코드그라운드 10 체스판 위의 길

2 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 }}