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

边栏推荐
- Tencent has five years of testing experience. It came to the interview to ask for 30K, and saw the so-called software testing ceiling
- Question bank and online simulation examination for special operation certificate of G1 industrial boiler stoker in 2022
- 总结全了,低代码还需要解决这4点问题
- How to choose the right server for website data collection?
- Do280 management application deployment --rc
- LeetCode 1399. Count the maximum number of groups
- TASK04|数理统计
- One job hopping up 8K, three times in five years
- This may be your last chance to join Tencent
- Maixll-Dock 使用方法
猜你喜欢

Registration for R2 mobile pressure vessel filling test in 2022 and R2 mobile pressure vessel filling free test questions

slf4j 简单实现
![[ue4] event distribution mechanism of reflective event distributor and active call event mechanism](/img/44/6a26ad24d56ddd5156f3a31fa7e0b9.jpg)
[ue4] event distribution mechanism of reflective event distributor and active call event mechanism

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

OdeInt与GPU

2022 G2 power station boiler stoker examination question bank and G2 power station boiler stoker simulation examination question bank

VR线上展览所具备应用及特色

"Target detection" + "visual understanding" realizes the understanding of the input image

Daily question - line 10

MySQL advanced -- you will have a new understanding of MySQL
随机推荐
Day 52 - tree problem
TCP server communication flow
This may be your last chance to join Tencent
Grey correlation cases and codes
2022 Shanghai safety officer C certificate examination question simulation examination question bank and answers
细数软件研发效能的七宗罪
Coinbase in a bear market: losses, layoffs, stock price plunges
Task04 | statistiques mathématiques
Odeint et GPU
软件研发的十大浪费:研发效能的另一面
Why is Hong Kong server most suitable for overseas website construction
Hololens2 development environment building and deploying apps
Registration for R2 mobile pressure vessel filling test in 2022 and R2 mobile pressure vessel filling free test questions
Haskell lightweight threads overhead and use on multicores
2022危险化学品生产单位安全生产管理人员题库及答案
总结全了,低代码还需要解决这4点问题
Do280 management application deployment --rc
25.k sets of flipped linked lists
[godot] unity's animator is different from Godot's animplayer
Embedded System Development Notes 80: using QT designer to design the main interface