栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

PAT1028.人口普查(Python)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

PAT1028.人口普查(Python)

解题思路

将生日合法的储存进字典中,最后将生日合法的用keys转化为列表,使用函数max及min查找年长与年轻的人,使用字典将年长与年轻映射的名字打印出来即可。

代码

n = eval(input())
​dic = {}
​for i in range(0,n):
​        s = input().split()
​        name = s[0]
​        birth = s[1].split('/')
​        #判断生日是否符合题意
​        if int(birth[0]) <= 1814 and int(birth[1]) <= 9 and int(birth[2]) < 6:
​                continue
​        if int(birth[0]) >= 2014 adn int(birth[1]) >= 9 and int(birth[2]) > 6:
​                continue
​        if int(birth[0]) > 2014:
​                continue
​        if int(birth[0]) < 1814:
​                continue
​        dic[birth[0]] = name
​birthlist = list(dic.keys())
​listLen = len(birthlist)
​maxBirth = max(birthlist)
​minBirth = min(birthlist)
​oldName = dic[minBirth]
​youngName = dic[maxBirth]
​print('{0} {1} {2}'.format(listLen,oldName,youngName))

暂时还没调试好,只能拿到15分,有3分非零返回,两分超时,暂时不知道是什么原因。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/916208.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号