当前位置:网站首页>[pat (basic level) practice] - [simple simulation] 1064 friends
[pat (basic level) practice] - [simple simulation] 1064 friends
2022-07-01 04:30:00 【IronmanJay】
List of articles
One 【 questions 】
- Class B
Two 【 Title number 】
- 1064 Number of friends (20 branch )
3、 ... and 【 Title Description 】
- 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 .
Four 【 Title Example 】
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 1 0 4 10^4 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 12sample output :
4
3 6 9 26
5、 ... and 【 Their thinking 】
- We can notice that , The range of figures given in the title is [ 0 ∼ 9999 ] [0\sim9999] [0∼9999], So the range of the sum of the digits is [ 0 ∼ 36 ] [0\sim36] [0∼36], So create a new one with a length of 37 The number of , Initialize to 0, Then scan each number in turn , And ask you to sum up , After finding out, change the corresponding position to 1, Note that only the original position is 0 To modify the , Because the title requires only one output . And record the number in it , Then we just need to output according to the requirements of the topic , Number of outputs first , Then traverse the array created before , If a position is 1, Just output the subscript of this position . In addition, you need to pay attention to the problem of spaces
6、 ... and 【 The final score 】
- 20 branch
7、 ... and 【 Code implementation 】
#include<stdio.h>
int main()
{
int n,count,temp,sum = 0;
scanf("%d",&n);
int nums[37] = {
0};
for(int i = 0;i<n;i++)
{
scanf("%d",&temp);
while(temp != 0)
{
sum += temp % 10;
temp /= 10;
}
if(nums[sum] == 0)
{
nums[sum]++;
count++;
}
sum = 0;
}
printf("%d\n",count);
for(int i = 0;i<37;i++)
{
if(nums[i] != 0)
{
printf("%d",i);
count--;
if(count != 0)
{
printf(" ");
}
}
}
return 0;
}
8、 ... and 【 Submit results 】

边栏推荐
- Learn Chapter 20 of vue3 (keep alive cache component)
- Odeint and GPU
- MallBook:后疫情时代下,酒店企业如何破局?
- LM小型可编程控制器软件(基于CoDeSys)笔记十九:报错does not match the profile of the target
- Software testing needs more and more talents. Why do you still not want to take this path?
- 2022年上海市安全员C证考试题模拟考试题库及答案
- One job hopping up 8K, three times in five years
- Do280 management application deployment --rc
- Task04 | statistiques mathématiques
- 嵌入式系统开发笔记81:使用Dialog组件设计提示对话框
猜你喜欢

使用WinMTR软件简单分析跟踪检测网络路由情况

It's settled! 2022 JD cloud summit of JD global technology Explorer conference see you in Beijing on July 13

2022 a special equipment related management (elevator) simulation test and a special equipment related management (elevator) certificate examination

This may be your last chance to join Tencent

In the innovation community, the "100 cities Tour" of the gold warehouse of the National People's Congress of 2022 was launched

Execution failed for task ‘:app:processDebugResources‘. > A failure occurred while executing com. and

Dual Contrastive Learning: Text Classification via Label-Aware Data Augmentation 阅读笔记
![[leetcode skimming] February summary (updating)](/img/62/0d0d9f11434e49d33754a2e4f2ea65.jpg)
[leetcode skimming] February summary (updating)

OdeInt与GPU

The junior college students were angry for 32 days, four rounds of interviews, five hours of soul torture, and won Ali's offer with tears
随机推荐
After many job hopping, the monthly salary is equal to the annual salary of old colleagues
Common thread methods and daemon threads
NFT:使用 EIP-2981 開啟 NFT 版稅之旅
Advanced application of ES6 modular and asynchronous programming
Introduction of Spock unit test framework and its practice in meituan optimization___ Chapter I
2022 t elevator repair new version test questions and t elevator repair simulation test question bank
Coinbase in a bear market: losses, layoffs, stock price plunges
分账技术赋能农贸市场,重塑交易管理服务效能
2022 gas examination question bank and online simulation examination
网站服务器:好用的网站服务器怎么选这五方面要关注
Spock单元测试框架介绍及在美团优选的实践___第一章
Maixll-Dock 使用方法
【人话版】WEB3黑暗森林中的隐私博弈
嵌入式系統開發筆記80:應用Qt Designer進行主界面設計
软件研发的十大浪费:研发效能的另一面
嵌入式系统开发笔记79:为什么要获取本机网卡IP地址
JMeter learning notes 2 - brief introduction to graphical interface
Odeint and GPU
跳槽一次涨8k,5年跳了3次...
How to ensure the idempotency of the high concurrency interface?