当前位置:网站首页>PAT B1064
PAT B1064
2022-06-25 19:57:00 【Madness makes freedom】
1064 Number of friends (20 branch )
If the sum of two integers is the same , It's called “ Number of friends ”, And the public one is theirs “ Friend ID number ”. for example 123 and 51 It's the number of friends , because 1+2+3 = 5+1 = 6, and 6 It's their friend ID number . Given some integers , Ask you to count how many different ID numbers they have .
Input format :
Enter the first line to give a positive integer N. The next line shows N A positive integer , Numbers are separated by spaces . Make sure that all numbers are less than 104.
Output format :
First, the first line outputs the number of different friend ID numbers in the given number ; The next line outputs these ID numbers in increasing order , The numbers are separated by a space , And there must be no extra space at the end of the line .
sample input :
8
123 899 51 998 27 33 36 12
sample output :
4
3 6 9 26This question directly uses one set The container stores the friend ID number , It's a lot easier .
#include <iostream>
#include <set>
using namespace std;
int main()
{
int n,num;
set<int> friend_id;
cin >> n;
while(n--)
{
cin >> num;
int sum=0;
while(num!=0)
{
int a=num%10;
num/=10;
sum+=a;
}
friend_id.insert(sum);
}
int len=friend_id.size();
cout << len << endl;
for(auto it=friend_id.begin();it!=friend_id.end();++it)
{
--len;
cout << *it;
if(len>0)
cout << ' ';
else
cout << endl;
}
return 0;
}
边栏推荐
- Vulnhub range - darkhole 1
- Google SEO external chain releases 50+ website platform sharing (e6zzseo)
- Analyse du code source du processus d'acquisition et de connexion hikaricp II
- Trend ea- fixed stop loss and profit per order
- PAT B1086
- On Oracle full stack virtual machine -- graalvm
- Est - il sûr d'ouvrir un compte avec de nouvelles dettes? Une faible Commission est - elle crédible?
- The functions in the applet page are better than those in app JS first execution solution
- PostgreSQL change table owner
- What are Baidu collection skills? 2022 Baidu article collection skills
猜你喜欢

Gbpnzd firm offer for 14 months, simulation for 19 months, test stable

Profile path and name

What should I pay attention to in GoogleSEO content station optimization?

Google SEO external chain releases 50+ website platform sharing (e6zzseo)

Does GoogleSEO need to change the friend chain? (e6zzseo)

ECS 7-day practical training camp (Advanced route) -- day03 -- ecs+slb load balancing practice

Server journey from scratch - Yu Zhongxian integrated version (IP access server, LNMP compilation and installation, Lua environment and socket expansion)

The native JS mobile phone sends SMS cases. After clicking the button, the mobile phone number verification code is sent. The button needs to be disabled and re enabled after 60 seconds

PAT B1076

Vulnhub range - darkhole 1
随机推荐
2.15(Multiple of 3 Or 5)
2020-12-09 laravel . Env file loading mechanism process
六、HikariConfig的配置解析
Processing method for uniapp or applet onload not receiving parameters
PAT B1056
Network security detection and prevention test questions (I)
How to understand var = a = b = C = 9? How to pre parse?
Est - il sûr d'ouvrir un compte avec de nouvelles dettes? Une faible Commission est - elle crédible?
The meanings of /32, /48, /64 in IPv6 addresses
Please do not call Page constructor in files
Install spoole
请问同花顺开户安全吗?
PHP database connection version1.1
Genicam gentl standard ver1.5 (1)
Vscode debugging PHP configuration Xdebug
Redis cache preheating & avalanche & breakdown & penetration
在打新债开户证券安全吗
Solidity contract address to wallet, wallet address to contract
PAT B1071
Jsonp function encapsulation