当前位置:网站首页>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;
}
边栏推荐
- Divine reversion EA
- Use of serialize() and serializearray() methods for form data serialization
- Simple native JS tab bar switching
- 1、 Hikaricp source code analysis of connection acquisition process I
- Is it safe to open an account with flush?
- Jsonp function encapsulation
- JS mobile phone and computer open different websites
- PAT B1071
- Bindgetuserinfo will not pop up
- Jsonp non homologous interaction (click trigger)
猜你喜欢

One night I worked as an XPath Terminator: XPath Helper Plus

Apifox simple understanding -- the integrator of web side testing

Vulnhub range - correlation:2

Miner's Diary: why should I go mining on April 5, 2021
Android Development Notes - Quick Start (from sqllite to room licentiousness) 2

ActiveMQ--CVE-2016-3088

Record Baidu search optimization thinking analysis

What are Baidu collection skills? 2022 Baidu article collection skills

Wechat applet swiper simple local picture display appears large blank

mysql load data infile
随机推荐
DARKHOLE 2
What should I pay attention to in GoogleSEO content station optimization?
五、HikariCP源码分析之初始化分析二
rmi-registry-bind-deserialization
MySQL view explanation
Arduino ide + esp8266+mqtt subscribe to publish temperature and humidity information
Wechat applet cloud function does not have dependency option installed
Force wechat page font size to be 100%
Tcp/ip test questions (III)
Determine whether it is a web page opened on wechat
三、HikariCP获取连接流程源码分析三
Appearance of object attributes
Dependency injection in PHP reflection implementation framework
PHP FPM, workman, spoole, golang simple performance test
ECS 7-day practical training camp (Advanced route) -- day03 -- ecs+slb load balancing practice
Alicloud centos8.0 installing mysql8
Laravel validation rule followed Role of auth:: id()
Genicam gentl standard ver1.5 (1)
Gbpnzd firm offer for 14 months, simulation for 19 months, test stable
Ali visual AI training camp -day05- creativity day - your image recognition project