티스토리 뷰

728x90

Tuples

Task
Given an integer, n, and n space-separated integers as input, create a tuple, t, of those n integers. Then compute and print the result of hash(t).

Note: hash() is one of the functions in the __builtins__ module, so it need not be imported.

Input Format

The first line contains an integer, n, denoting the number of elements in the tuple.
The second line contains n space-separated integers describing the elements in tuple t.

Output Format

Print the result of hash(t).

Sample Input 0

2
1 2

Sample Output 0

3713081631934410656

 

문제해석

입력된 값의 hash값을 구하여야 한다. 이 때 hash()는 Tuple의 내장함수로 따로 구현할 필요는 없다. 다만, 입력되는 값의 타입이 list이기 때문에 tuple 타입으로 변경해야 하는데 찾아보니 list와 tuple은 서로 상호호환이 된다고 한다. 즉, list(tuple) 또는 tuple(list) 이런식으로 간단히 타입변환이 가능하다.

 

문제풀이

hash() 내장함수를 사용하는 문제이기 때문에 특별히 생각해야 되는 부분은 없었다. 입력된 리스트를 tuple() 함수를 사용하여 함수로 변경한 후 hash() 함수를 통해 hash 값을 구하였다.

if __name__ == '__main__':
    n = int(raw_input())
    integer_list = map(int, raw_input().split())
        
    tuple_list = tuple(integer_list)
    print(hash(tuple_list))
728x90
LIST
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함