博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
day01_Sock Merchant
阅读量:5248 次
发布时间:2019-06-14

本文共 1083 字,大约阅读时间需要 3 分钟。

Sock Merchant

Function Description

Complete the sockMerchant function in the editor below. It must return an integer representing the number of matching pairs of socks that are available.

sockMerchant has the following parameter(s):

  • n: the number of socks in the pile
  • ar: the colors of each sock

Input Format

The first line contains an integer n , the number of socks represented in ar

The second line contains n space-separated integers describing the colors ar[i]  of the socks in the pile.

Constraints

 

Output Format

Return the total number of matching pairs of socks that John can sell.

Sample Input

910 20 20 10 10 30 50 10 20

Sample Output

3

Explanation

sock.png

John can match three pairs of socks.

from collections import Counter# Complete the sockMerchant function below.def sockMerchant(n, ar):    sum = 0    for values in Counter(ar).values():        sum += values // 2    return sumif __name__ == '__main__':    n = int(input())    ar = list(map(int, input().rstrip().split()))    result = sockMerchant(n, ar)    print(result)

 

转载于:https://www.cnblogs.com/wzs-python/p/11217675.html

你可能感兴趣的文章
Linux上安装Libssh2
查看>>
九.python面向对象(双下方法内置方法)
查看>>
go:channel(未完)
查看>>
[JS]递归对象或数组
查看>>
LeetCode(17) - Letter Combinations of a Phone Number
查看>>
Linux查找命令对比(find、locate、whereis、which、type、grep)
查看>>
路由器外接硬盘做nas可行吗?
查看>>
python:从迭代器,到生成器,再到协程的示例代码
查看>>
Java多线程系列——原子类的实现(CAS算法)
查看>>
在Ubuntu下配置Apache多域名服务器
查看>>
多线程《三》进程与线程的区别
查看>>
linux sed命令
查看>>
LeetCode 160. Intersection of Two Linked Lists
查看>>
html标签的嵌套规则
查看>>
[Source] Machine Learning Gathering/Surveys
查看>>
HTML <select> 标签
查看>>
类加载机制
查看>>
tju 1782. The jackpot
查看>>
HTML5与CSS3基础(五)
查看>>
WinDbg调试C#技巧,解决CPU过高、死锁、内存爆满
查看>>