当前位置:网站首页>[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 】
边栏推荐
- 使用scroll-view实现滑块视图可能遇到的问题及其解决方法
- 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
- TASK04|数理统计
- ThreeJS开篇
- In the innovation community, the "100 cities Tour" of the gold warehouse of the National People's Congress of 2022 was launched
- Software testing needs more and more talents. Why do you still not want to take this path?
- 细数软件研发效能的七宗罪
- Offline installation of Wireshark 2.6.10
- 【人话版】WEB3黑暗森林中的隐私博弈
- TASK04|數理統計
猜你喜欢
Question bank and online simulation examination for special operation certificate of G1 industrial boiler stoker in 2022
Extension fragment
JMeter learning notes 2 - brief introduction to graphical interface
2022 a special equipment related management (elevator) simulation test and a special equipment related management (elevator) certificate examination
类和对象收尾
Concurrent mode of different performance testing tools
Custom components in applets
【深度学习】(4) Transformer 中的 Decoder 机制,附Pytorch完整代码
[godot] unity's animator is different from Godot's animplayer
Registration of P cylinder filling examination in 2022 and analysis of P cylinder filling
随机推荐
JD intelligent customer service Yanxi intention system construction and intention recognition technology introduction
How to choose the right server for website data collection?
How to ensure the idempotency of the high concurrency interface?
Introduction of Spock unit test framework and its practice in meituan optimization___ Chapter I
嵌入式系統開發筆記80:應用Qt Designer進行主界面設計
Qt development experience tips 226-230
2022年煤气考试题库及在线模拟考试
Possible problems and solutions of using scroll view to implement slider view
2022 gas examination question bank and online simulation examination
Threejs opening
Maixll-Dock 快速上手
[recommended algorithm] C interview question of a small factory
Use winmtr software to simply analyze, track and detect network routing
Jenkins automatically cleans up construction history
Seven crimes of counting software R & D Efficiency
[godot] unity's animator is different from Godot's animplayer
Question bank and answers for chemical automation control instrument operation certificate examination in 2022
Dual Contrastive Learning: Text Classification via Label-Aware Data Augmentation 阅读笔记
一些小知识点
Maixll dock quick start