PAT乙级 1064 朋友数

PAT乙级 1064 朋友数
把当时的代码放出来,大家共同学习,互相帮助
题目:
在这里插入图片描述
输入样例:

8
123 899 51 998 27 33 36 12

输出样例:

4
3 6 9 26

代码如下(Python):

# PAT 1064
num_count = int(input())
number_lst = input().split(' ')
friend_numb_lst = []
for i in number_lst:
    friend_numb = 0
    for j in range(len(i)):
        friend_numb += int(i[j])
    if friend_numb not in friend_numb_lst:
        friend_numb_lst.append(friend_numb)
friend_numb_lst.sort()
friend_numb_lst = list(map(str, friend_numb_lst))
print(len(friend_numb_lst))
print(' '.join(friend_numb_lst))
发布了65 篇原创文章 · 获赞 25 · 访问量 1037

猜你喜欢

转载自blog.csdn.net/chongchujianghu3/article/details/104984254
今日推荐