当前位置:网站首页>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;
}
边栏推荐
- 在打新债开户证券安全吗?低佣金靠谱吗
- Wechat applet swiper simple local picture display appears large blank
- 1、 Hikaricp source code analysis of connection acquisition process I
- PHP FPM, workman, spoole, golang simple performance test
- Ali visual AI training camp -day03- construction of electronic photo album (face and expression recognition)
- Mqtt+ardunio+esp8266 development (excluding mqtt server deployment)
- JS advanced
- Thymleaf template configuration analysis
- Web components - Basics
- MySQL prompt performance_ Schema missing table
猜你喜欢

On Oracle full stack virtual machine -- graalvm

Arduino ide + esp8266+mqtt subscribe to publish temperature and humidity information

PHP Chinese regular

New features of php7

Vulnhub range the planes: mercury

Lilda Bluetooth air conditioning receiver helps create a more comfortable road life

Bindgetuserinfo will not pop up

Embark on a new journey and reach the world with wisdom

Principles of MySQL clustered index and non clustered index

ECS 7-day practical training camp (Advanced route) -- day01 -- setting up FTP service based on ECS
随机推荐
Pat b1054 average (20 points)
MySQL prompt performance_ Schema missing table
Browser performance optimization (19)
Vulnhub range - correlation:2
Applet multi image to Base64 upload
RPM package installation command
Panda weekly -2022/02/18
Analyse du code source du processus d'acquisition et de connexion hikaricp II
System optimization method
Error record: preg_ match(): Compilation failed: range out of order in character class at offset 13
Miner's Diary: why should I go mining on April 5, 2021
打新债网上开户安全吗,需要注意什么
Network security detection and prevention test questions (II)
Tcp/ip test questions (III)
Vulnhub range the planes: mercury
Genicam gentl standard ver1.5 (1)
Randomly generate 100 non repeating numbers between 1 and 150 and put them in the array
Jsonp non homologous interaction (click trigger)
Network security detection and prevention test questions (V)
Please do not call Page constructor in files