首页 > 其他 > 详细

1120 Friend Numbers

时间:2020-03-18 20:36:58      阅读:47      评论:0      收藏:0      [点我收藏+]

英文版题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805352925609984

中文版题目:https://pintia.cn/problem-sets/994805260223102976/problems/994805267416334336

 1 #include<iostream>
 2 #include<map>
 3 using namespace std;
 4 
 5 int main() {
 6     int n,cnt = 0,flag = 0;
 7     cin>>n;
 8     map<int,bool> mp;
 9     for(int i = 0; i < n; ++i) {
10         int t,sum = 0;
11         cin>>t;
12         while(t) {
13             sum += t % 10;
14             t /= 10;
15         }
16         if(mp[sum] == false) cnt++,mp[sum] = true;
17     }
18     cout<<cnt<<endl;
19     for(auto it:mp) {
20         if(flag++ != 0) printf(" ");
21         cout<<it.first;
22     }
23     return 0;
24 }

技术分享图片

 

1120 Friend Numbers

原文:https://www.cnblogs.com/keep23456/p/12519927.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!