当前位置:网站首页>刷题-洛谷-P1059 明明的随机数
刷题-洛谷-P1059 明明的随机数
2022-07-25 13:32:00 【宋向上_UP】
P1059 明明的随机数-C语言
1、题目

2、解题过程
结果:
//洛谷 P1059 明明的随机数
#include <stdio.h>
#define NUM 100 //初始随机数的最大数目
int main()
{
int n;//表示初始随机数的数目 N<=100
int m=0;//表示不同随机数的数目-1
int random[NUM];//初始随机数
int random_new[NUM];//不同随机数
int i,j;
int temp;//用于排序时的临时值
int k;//不同随机数的数量
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;//方便理解
//冒泡排序 从小到大
for (i = 0; i < k; i++) {
//要对k个数进行k-1轮冒泡排序
for (j = 0; j < k-i-1; j++) {
if (random_new[j] > random_new[j+1]) {
//交换
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;
}
边栏推荐
- Summary of Niuke forum project deployment
- Introduction and features of numpy (I)
- Redis visualizer RDM installation package sharing
- Hcip day 10 notes
- C # basic learning (XXIII)_ Forms and events
- 2022年下半年软考信息安全工程师如何备考?
- 基于百问网IMX6ULL_PRO开发板移植LCD多点触摸驱动(GT911)
- 0720RHCSA
- 【GCN-CTR】DC-GNN: Decoupled GNN for Improving and Accelerating Large-Scale E-commerce Retrieval WWW22
- Immortal software in the computer that I don't want to delete all my life
猜你喜欢

Esp32-c3 is based on blinker lighting control 10 way switch or relay group under Arduino framework

C#基础学习(二十三)_窗体与事件

0716RHCSA

Friends let me see this code

QGIS loading online map: Gaode, Tiandi map, etc

嵌入式代码如何进行重构?

为提高效率使用ParallelStream竟出现各种问题

Shell common script: check whether a domain name and IP address are connected
详解浮点数的精度问题

arm架构移植alsa-lib和alsa-utils一路畅通
随机推荐
Discussion on principle and application technology of MLIR
嵌入式代码如何进行重构?
TCP的拥塞控制
业务可视化-让你的流程图'Run'起来(3.分支选择&跨语言分布式运行节点)
音视频技术开发周刊 | 255
【AI4Code】CodeX:《Evaluating Large Language Models Trained on Code》(OpenAI)
My creation anniversary
机器学习强基计划0-4:通俗理解奥卡姆剃刀与没有免费午餐定理
央行数研所穆长春:数字人民币可控匿名是维护公众利益和金融安全的客观需要
Online Learning and Pricing with Reusable Resources: Linear Bandits with Sub-Exponential Rewards: Li
Brpc source code analysis (III) -- the mechanism of requesting other servers and writing data to sockets
0719RHCSA
6W+字记录实验全过程 | 探索Alluxio经济化数据存储策略
Peripheral system calls SAP's webapi interface
mujoco_py中文文档
Django 2 ----- database and admin
0717RHCSA
Prepare for 2022 csp-j1 2022 csp-s1 preliminaries video set
Convolutional neural network model -- alexnet network structure and code implementation
全网最简单解决方式1045-Access denied for user [email protected](using password:YES)