当前位置:网站首页>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;
}
边栏推荐
- 刷题-洛谷-P1089 津津的储蓄计划
- Hcip eighth day experiment
- 手写jdbc的使用步骤?
- Pytest.mark.parameterize and mock use
- 【Platform IO编译Hifive1-revB】*** [.pio\build\hifive1-revb\src\setupGPIO.o] Error 1的解决办法
- Workplace "digital people" don't eat or sleep 007 work system, can you "roll" them?
- Common methods of arrays
- 刷题-洛谷-P1151 子数整数
- 并发编程之AQS
- HTTP cache tongtianpian, there may be something you want
猜你喜欢

GCD details

Discussion on principle and application technology of MLIR

【力扣】645.错误的集合

leetcode--四数相加II

Applet sharing function

LabVIEW的内部错误
![[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

Applet enterprise red envelope function

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

leetcode1 --两数之和
随机推荐
刷题-洛谷-P1152 欢乐的跳
QGIS loading online map: Gaode, Tiandi map, etc
刷题-洛谷-P1046 陶陶摘苹果
GCD details
【配置Hifive1-revB】设备管理器中不识别端口,Can not connect to J-Link via USB的解决办法
Okaleido上线聚变Mining模式,OKA通证当下产出的唯一方式
HTTP cache tongtianpian, there may be something you want
剑指offer专项突击版第10天
【力扣】645.错误的集合
Error of Tencent cloud [100007] this env is not enable anonymous login
Numpy快速入门
window unbutu20 LTS apt,wget 安装时 DNS 解析错误
"Digital security" alert NFT's seven Scams
【服务器数据恢复】HP EVA服务器存储RAID信息断电丢失的数据恢复
Based on Baiwen imx6ull_ Ap3216 experiment driven by Pro development board
Canvas judgment content is empty
Install oh my Zsh
LabVIEW的内部错误
2022年下半年软考信息安全工程师如何备考?
The interviewer asked me: how much do you know about MySQL's storage engine?