当前位置:网站首页>[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 】

边栏推荐
- 高并发下接口幂等性如何保证?
- 嵌入式系统开发笔记79:为什么要获取本机网卡IP地址
- How to do the performance pressure test of "Health Code"
- MySQL function variable stored procedure
- 测量三相永磁同步电机的交轴直轴电感
- 采购数智化爆发在即,支出宝'3+2'体系助力企业打造核心竞争优势
- Daily question - line 10
- Browser top loading (from Zhihu)
- Programs and processes, process management, foreground and background processes
- NFT: utilisez EIP - 2981 pour commencer un voyage de redevances NFT
猜你喜欢

2022 t elevator repair new version test questions and t elevator repair simulation test question bank

TASK04|數理統計

扩展-Fragment

2022年T电梯修理题库及模拟考试

Registration of P cylinder filling examination in 2022 and analysis of P cylinder filling

【人话版】WEB3黑暗森林中的隐私博弈
![[send email with error] 535 error:authentication failed](/img/58/8cd22fed1557077994cd78fd29f596.png)
[send email with error] 535 error:authentication failed

Task04 | statistiques mathématiques

2022年上海市安全员C证考试题模拟考试题库及答案

slf4j 简单实现
随机推荐
OSPF notes [dr and bdr]
Hololens2 development environment building and deploying apps
"Target detection" + "visual understanding" realizes the understanding of the input image
[recommended algorithm] C interview question of a small factory
Valid @suppresswarnings warning name
Knowledge supplement: redis' basic data types and corresponding commands
How to choose the right server for website data collection?
Question bank and answers for chemical automation control instrument operation certificate examination in 2022
[today in history] June 30: von Neumann published the first draft; The semiconductor war in the late 1990s; CBS acquires CNET
Jenkins automatically cleans up construction history
Common thread methods and daemon threads
CF1638E colorful operations
OSPF notes [multiple access, two multicast addresses with OSPF]
After many job hopping, the monthly salary is equal to the annual salary of old colleagues
How to do the performance pressure test of "Health Code"
Browser top loading (from Zhihu)
使用WinMTR软件简单分析跟踪检测网络路由情况
2022年聚合工艺考试题及模拟考试
2022 Shanghai safety officer C certificate examination question simulation examination question bank and answers
Mallbook: how can hotel enterprises break the situation in the post epidemic era?