当前位置:网站首页>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;
}
边栏推荐
- Applet enterprise red envelope function
- 【配置Hifive1-revB】设备管理器中不识别端口,Can not connect to J-Link via USB的解决办法
- hcip第八天实验
- 刷题-洛谷-P1146 硬币翻转
- Pytest.mark.parameterize and mock use
- Uncaught SyntaxError: Octal literals are not allowed in strict mode.
- Mxnet implementation of densenet (dense connection network)
- 说说对hashcode和equals方法的理解?
- [force deduction] 1030. Arrange matrix cells in distance order
- Leetcode 113. path sum II
猜你喜欢

职场「数字人」不吃不睡007工作制,你「卷」得过它们吗?

「数字安全」警惕 NFT的七大骗局

【力扣】1030.距离顺序排列矩阵单元格

刷题-洛谷-P1059 明明的随机数

Mxnet implementation of densenet (dense connection network)

6.27 uniapp project history

Sports luxury or safety luxury? Which type of Asian Dragon and Volvo S60 should we start with?

What is your revenue rank among global developers in 2022?

The whole process of 6w+ word recording experiment | explore the economical data storage strategy of alluxio

Based on Baiwen imx6ull_ Ap3216 experiment driven by Pro development board
随机推荐
移动端网站,独立APP,网站排名策略有哪些?
QGIS loading online map: Gaode, Tiandi map, etc
手写jdbc的使用步骤?
JS Array indexOf includes sort() 冒号排序 快速排序 去重和随机样本 random
ES6 array de duplication new set()
Applet sharing function
【力扣】1030.距离顺序排列矩阵单元格
Gym安装、调用以及注册
Congestion control of TCP
Install mujoco and report an error: distutils.errors DistutilsExecError: command ‘gcc‘ failed with exit status 1
并发编程之阻塞队列
Applet enterprise red envelope function
Hcip eighth day experiment
"Digital security" alert NFT's seven Scams
2022年下半年软考信息安全工程师如何备考?
刷题-洛谷-P1035 级数求和
QGIS加载在线地图:高德、天地图等
电脑里一辈子都不想删的神仙软件
Pytest.mark.parameterize and mock use
From input URL to web page display