首页 > 热点网站统计 Python (有疑惑!!!)
头像
RainYang
发布于 今天 09:54 四川
+ 关注

热点网站统计 Python (有疑惑!!!)

题目详情:https://www.nowcoder.com/discuss/368536502547042304

input_str = [
    "news.qq.com",
    "www.cctv.com",
    "1",
    "www.huawei.com",
    "www.huawei.com",
    "2",
    "3",
]
url_str = []
ans_str = []
for i_str in input_str:
    if i_str.find("."):
        url_str.append(i_str)
    elif all("0" <= s <= "9" for s in i_str):
        cnt = Counter(url_str)
        for k, _ in cnt.most_common(int(i_str)):
            ans_str.append(k)
        #
        print(",".join(ans_str))
        #
        ans_str = []
    else:
        pass

#########################################################################################

#########################################################################################

#########################################################################################

while True:
    input_str = input()
    #
    url_str = []
    ans_str = []
    if input_str.find("."):
        url_str.append(input_str)
    elif all("0" <= s <= "9" for s in input_str):
        cnt = Counter(url_str)
        for k, _ in cnt.most_common(int(input_str)):
            ans_str.append(k)
        #
        print(",".join(ans_str))
        #
        ans_str = []
    else:
        pass

#########################################################################################

#########################################################################################

#########################################################################################

疑惑:华为OD机试中这道题是怎么处理输入的?有没有知道的朋友???

全部评论

(0) 回帖
加载中...
话题 回帖

近期热帖

近期精华帖

热门推荐