PAT 1120 Friend Numbers

【PAT】A1120 Friend Numbers【散列】 Two integers are called “friend numbers” if they share the same sum of their digits, and the sum is their “friend ID”. For example, 123 and 51 are friend numbers since 1+2+3 = 5+1 = 6, and 6 is their ... 阅读详情

Two integers are called "friend numbers" if they share the same sum of their digits, and the sum is their "friend ID". For example, 123 and 51 are friend numbers since 1+2+3 = 5+1 = 6, and 6 is their friend ID. Given some numbers, you are supposed to count the number of different friend ID's among them.

Input Specification:

Each input file contains one test case. For each case, the first line gives a positive integer N. Then N positive integers are given in the next line, separated by spaces. All the numbers are less than 104.

Output Specification:

For each case, print in the first line the number of different friend ID's among the given integers. Then in the second line, output the friend ID's in increasing order. The numbers must be separated by exactly one 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 26

代码长度限制

16 KB

时间限制

400 ms

内存限制

64 MB

这个没什么好说的

#include <iostream>
#include <map>
#include <vector>
using namespace std;

int n;
map<int,int> hmap;

int sum(int x)
{
	int res=0;
	while(x)
	{
		res+=x%10;
		x/=10;
	}
	return res;
}

int main()
{
	int x;
	cin>>n;
	while(n--)
	{
		cin>>x;
		hmap[sum(x)]++;
	}
	vector<int> v;
	for(auto x:hmap)
	{
		v.push_back(x.first);
	}
	cout<<v.size()<<endl;
	for(int i=0 ; i<v.size()-1 ; i++)
		cout<<v[i]<<" ";
	cout<<v[v.size()-1];
	return 0;
}

HBuilderX远程开发环境配置:Windows SSH连接实操 详细介绍如何在Windows系统中通过SSH连接远程服务器,配置HBuilderX进行高效远程开发,提升编码协作效率。全程实操演示,轻松掌握hbuilderx与远程环境的无缝对接。 阅读详情

相关推荐

闲人闲谈PS之一项目库存跨公司业务STO解决方案--SAP闲人的开篇

写这篇文章之前,简单说一下发这篇文章的动机。也算是在SAP这一行干了快10多年,在对一个模块了解越来越深入,越发觉自己的SAP知识浅薄。总的来说,和多数顾问一样,对于**标准功能**的应用业务场景理解还是存在或多或少的知识盲区。 因为一个偶然,看到SAP团子君的文章,分享了很多干货文章。这也是自己一直想做的时候,不管水平高低与否,分享本身就意味着提升。好了废话不多说,先在优快云上发一篇吧,困惑自己将近10年的问题的解决方案。 业务场景:在项目型企业中,通常会有这样的业务,母公司和客...

SAP闲人的博客 9267

PAT 1120 Friend Numbers java 版

PAT 1120 Friend Numbers java 版

说文科技,做有态度的研究。 707

告别JTAG!用Artix-7和SPI Flash实现FPGA远程升级的保姆级教程

本文详细介绍了如何利用Artix-7 FPGA和SPI Flash实现FPGA远程升级(OTA)的完整方案。通过硬件连接、Vivado工程配置和STM32模拟更新等步骤,帮助开发者告别传统的JTAG烧录方式,实现高效、安全的远程固件更新,特别适用于嵌入式系统开发中的现场维护场景。

weixin_33964987的博客 364

pat 1120. Friend Numbers

原题链接:https://www.patest.cn/contests/pat-a-practise/1120 1120. Friend Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者

messenger的博客 289

spark 适配达梦数据库

spark 适配达梦数据库 版本 spark3.0.0 scala2.12.10 DM Database Server 64 V8 步骤一: 引驱动包: SBT方式: "com.dameng" % "Dm8JdbcDriver18" % "8.1.0.157", maven方式: <dependency> <groupId>com.dameng</groupId> <artifactId>Dm8JdbcDriver18</artifac

_@Eva@_的博客 2090

Blender关于GIS安装及使用天地图

Blender下载安装及GIS插件的安装及使用

Miss_SQ的博客 6971

PAT 甲级 1120  Friend Numbers

1120 Friend Numbers (20 point(s)) Two integers are called "friend numbers" if they share the same sum of their digits, and the sum is their "friend ID". For example, 123 and 51 are friend numbers sin...

漫浸天空的雨色的备忘录~ 572

YOLO11涨点优化:SPPF原创自研创新 | SPPF创新结构,重新设计全局平均池化层和全局最大池化层,增强全局视角信息和不同尺度大小的特征

SPPF_improve利用全局平均池化层和全局最大池化层,加入一些全局背景信息和边缘信息,从而获取全局视角信息并减轻不同尺度大小所带来的影响

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 1869

PAT A1120 Friend Numbers

PAT A1120 Friend Numbers Sample Input: 8 123 899 51 998 27 33 36 12 Sample Output: 4 3 6 9 26 思路 1: 求出每个输入数各位数的和,insert入set 遍历set输出 code 1: #include <iostream> #include <set> usin...

qq_42347617的博客 177

时频分析之短时傅里叶变换(STFT)

本文利用MATLAB自带的spectrogram函数对信号做短时傅里叶变换。首先介绍了短时傅里叶变换(STFT)的背景及意义;其次,对spectrogram函数的用法以及变量的含义做了详细的解释;最后,利用MATLAB编写程序实现了信号的STFT。

总结论文中的算法并给出论文的复现代码 7万+

SAP BSIS:总账未清项表(Open Items)总账未清项 包含哪些业务 请给以举例说明

SAP总账未清项是指需要未来核销的会计行项目,仅适用于勾选"未清项管理"的总账科目。典型业务场景包括:供应商预付款(借方未清项)、员工备用金(借方未清项)、客户预收款(贷方未清项)和保险理赔(借方未清项)。系统通过表BSIS/BSAS跟踪未清项,支持明细追踪和账实核对。核心价值在于提供总账级别的明细管理能力,确保往来款项完整清账,简化对账流程,满足特殊业务管理需求。可通过FBL3N事务码查询和管理所有总账未清项。

金牌架构师 724

PAT 1120 Friend Numbers python解法

1120 Friend Numbers (20 分) Two integers are called “friend numbers” if they share the same sum of their digits, and the sum is their “friend ID”. For example, 123 and 51 are friend numbers since 1+2+3...

qq_36936510的博客 263

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

pat1120 Friend Numbers

1120Friend Numbers(20分) Two integers are called "friend numbers" if they share the same sum of their digits, and the sum is their "friend ID". For example, 12...

qq_42681421的博客 147

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

【PAT甲级 - C++题解】1120 Friend Numbers

📣专栏定位:为想考甲级PAT的小伙伴整理常考算法题解,祝大家都能取得满分!

Newin2020的博客 774

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

PAT——1120 Friend Numbers 甲级

1120 Friend Numbers题目题意代码解析AC代码参考 题目 https://pintia.cn/problem-sets/994805342720868352/problems/994805352925609984 题意 给出n个数字,计算各位数字之和,最后不重复地升序输出 代码解析 计算各位数字之和采用遍历字符串,将结果放入set中,最后直接输出即可 注意,set是不重复的、有序的(升序),所以直接输出即可,不需要排序 AC代码 #include<bits/stdc++.h> u

ljhsq的博客 129

PAT 甲级 1120 Friend Numbers

1120 Friend Numbers Two integers are called “friend numbers” if they share the same sum of their digits, and the sum is their “friend ID”. For example, 123 and 51 are friend numbers since 1+2+3 = 5+1 ...

cyberickk blog 185

PAT甲级 1120 Friend Numbers

浙江大学PAT题目解答内容. Contribute to ZouJiu1/PAT development by creating an account on GitHub.GitHub - ZouJiu1/PAT: 浙江大学PAT题目解答内容。

邹九的个人博客 190

PAT_A_1120 Friend Numbers

此题比较基础,题意:给一个int类型的数,然后求每位的和(id),求所给的一组数中id有多少种,打印种类个数和所有id 思路:把求得的id插入set集合,set集合不允许有重复的元素,而且是自动排好序的,故适合解此题 代码: #include<iostream> #include<algorithm> #include<set> using namesp...

qq_42152681的博客 150

PAT A1120. Friend Numbers

1120. Friend Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Two integers are called "friend numbers" if they share the

u014226072的专栏 280
上一篇: PAT 1167 Cartesian Tree
下一篇: PAT 1125 Chain the Ropes
CocaCona
博客等级 码龄5年 21粉丝 11原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值