当前位置:网站首页>Brush questions - Luogu -p1059 clear random number
Brush questions - Luogu -p1059 clear random number
2022-07-25 13:46:00 【Song Xiangshang_ UP】
P1059 A clear random number -C Language
1、 subject

2、 The problem solving process
result :
// Luogu P1059 A clear random number
#include <stdio.h>
#define NUM 100 // The maximum number of initial random numbers
int main()
{
int n;// Represents the number of initial random numbers N<=100
int m=0;// Represents the number of different random numbers -1
int random[NUM];// Initial random number
int random_new[NUM];// Different random numbers
int i,j;
int temp;// Temporary value for sorting
int k;// The number of different random numbers
scanf("%d", &n);
scanf("%d", &random[0]);
random_new[m] = random[0];
for (i = 1; i < n; i++) {
scanf("%d", &random[i]);
for (j = 0; j < i; j++) {
if (random[i] == random[j]) {
break;
}
}
if (j == i) {
m++;
random_new[m] = random[i];
}
}
k = m + 1;// Easy to understand
// Bubble sort From small to large
for (i = 0; i < k; i++) {
// Right k The number goes on k-1 Round bubble sorting
for (j = 0; j < k-i-1; j++) {
if (random_new[j] > random_new[j+1]) {
// In exchange for
temp = random_new[j];
random_new[j] = random_new[j+1];
random_new[j+1] = temp;
}
}
}
printf("%d\n", m + 1);
for (i = 0; i < m + 1; i++) {
printf("%d ", random_new[i]);
}
return 0;
}
边栏推荐
- Sword finger offer special assault edition day 10
- Hcip day 9 notes
- [platform IO compile hifive1 revb] * * * [.pio\build\hifive1 revb\src\setupgpio.o] solution to error 1
- Install oh my Zsh
- 说说对hashcode和equals方法的理解?
- Uncaught SyntaxError: Octal literals are not allowed in strict mode.
- QGIS加载在线地图:高德、天地图等
- @Classmethod decorator
- ADB connects to Xiaomi mobile phone via Wi Fi
- Pytest.mark.parameterize and mock use
猜你喜欢

Excel record macro

刷题-洛谷-P1150 Peter的烟

刷题-洛谷-P1161 开灯

pytest.mark.parametrize及mock使用

Canal realizes MySQL data synchronization

Brush questions - Luogu -p1046 Tao Tao picking apples

Package management apt, dpkg

Applet enterprise red envelope function
![[platform IO compile hifive1 revb] * * * [.pio\build\hifive1 revb\src\setupgpio.o] solution to error 1](/img/a1/de197464e2a735d7ef012cea780da5.png)
[platform IO compile hifive1 revb] * * * [.pio\build\hifive1 revb\src\setupgpio.o] solution to error 1

Leetcode1 -- sum of two numbers
随机推荐
运动豪华还是安全豪华?亚洲龙与沃尔沃S60该入手哪款?
sieve of eratosthenes
NoSQL,关系型数据库,行列数据库对比、类比
Canvas判断内容为空
手写jdbc的使用步骤?
移动端网站,独立APP,网站排名策略有哪些?
DNS resolution error during windows unbutu20 lts apt, WGet installation
What should I do if the high-level MySQL server cannot be installed and I forget the password (MySQL 8.0.29)?
飞盘局有多快乐?2022年轻人新潮运动报告
Excel add key run macro
Sports luxury or safety luxury? Which type of Asian Dragon and Volvo S60 should we start with?
Introduction and features of numpy (I)
领域驱动模型设计与微服务架构落地-模型设计
并发编程之AQS
How to refactor embedded code?
「数字安全」警惕 NFT的七大骗局
Basic knowledge of binary tree
Int array get duplicate data
@classmethod 装饰器
mujoco_ Py Chinese document