"코드그라운드 1 숫자 골라내기"의 두 판 사이의 차이

(새 문서: 분류: 코드그라운드 ==Java== 분류: Java <source lang='java'> /* You should use the statndard input/output in order to receive a score properly. Do not use file input...)
 
잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
(다른 사용자 한 명의 중간 판 11개는 보이지 않습니다)
1번째 줄: 1번째 줄:
[[분류: 코드그라운드]]
[[분류: 코드그라운드 연습문제]]
==개요==
;코딩그라운드 1 숫자 골라내기
 
{{CG연습문제 헤더}}
{{CG연습문제 1페이지}}
|}
 
==Java==
==Java==
[[분류: Java]]
<syntaxhighlight lang='java'>
<source lang='java'>
/*
/*
You should use the statndard input/output
You should use the statndard input/output
58번째 줄: 64번째 줄:
}
}
}
}
</source>
</syntaxhighlight>
 
==Python==
<syntaxhighlight lang='python'>
'''
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 sys
'''
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 open() method.
You may remove the comment symbols(#) in the below statement and use it.
But before submission, you must remove the open function or rewrite comment symbols(#).
'''
#inf = open('input.txt');
inf = sys.stdin
T = inf.readline();
for t in range(0, int(T)):
#############################################################################################
#
#  Implement your algorithm here.
#  The answer to the case will be stored in variable Answer.
#
#############################################################################################
    N = int(input())
    s = set()
    for i in map(int,input().split()):
        if i in s:
            s.remove(i)
        else:
            s.add(i)
    Answer = -1
    for i in s:
        if( Answer == -1 ): Answer = i;
        else: Answer = Answer^i;
    # Print the answer to standard output(screen).
    print('Case #%d' %(int(t)+1))   
    print(Answer)
inf.close()
</syntaxhighlight>

2021년 7월 31일 (토) 11:00 기준 최신판

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);
		}
	}
}

3 Python[ | ]

'''
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 sys
'''
	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 open() method.
	You may remove the comment symbols(#) in the below statement and use it.
	But before submission, you must remove the open function or rewrite comment symbols(#).
'''
#inf = open('input.txt');
inf = sys.stdin 
T = inf.readline();
for t in range(0, int(T)):
	#############################################################################################
	#
	#  Implement your algorithm here.
	#  The answer to the case will be stored in variable Answer.
	#
	#############################################################################################
    N = int(input())
    s = set()
    for i in map(int,input().split()):
        if i in s:
            s.remove(i)
        else:
            s.add(i)
    Answer = -1
    for i in s:
        if( Answer == -1 ): Answer = i;
        else: Answer = Answer^i;
    # Print the answer to standard output(screen).
    print('Case #%d' %(int(t)+1))    
    print(Answer)
inf.close()
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}