https://www.hackerrank.com/challenges/sock-merchant/problem
HackerRank - Sock Merchant
#!/bin/python3
import math
import os
import random
import re
import sys
def sockMerchant(n, ar):
socks = {}
countPair = 0
for color in ar:
try:
socks[color] += 1
except:
socks[color] = 1
for color in socks:
countPair += int(socks[color] / 2)
return countPair
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input())
ar = list(map(int, input().rstrip().split()))
result = sockMerchant(n, ar)
fptr.write(str(result) + '\n')
fptr.close()
'알고리즘 문제 풀기 > HackerRank' 카테고리의 다른 글
HackerRank - Electronics Shop (0) | 2019.01.30 |
---|---|
HackerRank - Drawing Book (0) | 2019.01.29 |
HackerRank - Bon Appétit (0) | 2019.01.27 |
HackerRank - Day of the Programmer (0) | 2019.01.25 |
HackerRank - Migratory Birds (0) | 2019.01.24 |