当前位置:网站首页>[programming question] clear random number
[programming question] clear random number
2022-04-22 01:49:00 【River University of Technology】
Mingming generated a 1 To 500 Random integer between . Please delete the duplicate numbers , That is, only one of the same numbers is retained , Take out the rest of the same number , And then sort the numbers from small to large , Output according to the arranged order .
Data range : , The size of the input number meets
Input description :
In the first line, enter the number of random integers N . Next N Line enter an integer for each line , Represents the random number clearly generated . For the specific format, please refer to the following " Example ".
Output description :
Output multiple lines , Indicates the result of input data processing
Input example 1:
3 2 2 1
Output example 1:
1 2
Example illustrate 1:
Enter an explanation : The first number is 3, That's what this little example is about N=3, It's computer generated 3 individual 1 To 500 Random integer between , Next, a random number per line , common 3 That's ok , That's what it is 3 A random number is : 2 2 1 So the output of the sample is : 1 2
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
boolean[] arr = new boolean[501];
for(int i = 0; i < N; i++) {
arr[sc.nextInt()] = true;
}
for(int i = 1; i < 501; i++) {
if(arr[i]) {
System.out.println(i);
}
}
}
}
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int N;
scanf("%d", &N);
vector<int> ans(N);
for(int i = 0; i < N; i++) {
scanf("%d", &ans[i]);
}
sort(ans.begin(), ans.end());
printf("%d\n", ans[0]);
int pre = ans[0];
for(int i = 1; i < N; i++) {
if(pre != ans[i]) {
printf("%d\n", ans[i]);
pre = ans[i];
}
}
return 0;
}
版权声明
本文为[River University of Technology]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220145286441.html
边栏推荐
- Ali Daniel collates, Android interview multiple-choice questions
- 【lua编程 控制手机进行聊天】--用于养号、可以放下手进行自动化聊天养号了
- Judge whether it is the sum of squares
- [Acwing] 第 8 场周赛
- 新内核版本的EasyCVR如何设置ts切片文件大小?
- AnatomyNet: Deep Learning for Fast and Fully Automated Whole-volume Segmentation of Head and Neck An
- 718. 最长重复子数组
- kubernetes gvk显示现象
- Ugui -- inputfield text input control
- Code source daily question div1 (601-607)
猜你喜欢

MATLAB实现多元正态Copula分布

Phy6222 domestic low power multi protocol Bluetooth SOC chip
![[ing] matlab Toolkit - detailed explanation of dynamic copula toolbox 3.0](/img/de/e498b78c0a03d508422aa2dee89ccf.png)
[ing] matlab Toolkit - detailed explanation of dynamic copula toolbox 3.0

What do you know about the ADB order in 2022? A 2000 word detailed ADB command is coming

VMware virtual machine installation detailed tutorial network NAT and bridge configuration

Station B charging | charging more than 1500 a week, Yinfa up is the new dark horse of station B?

Leetcode1470. Rearrange array

C# UserControl造成内存泄漏

分布式事务解决方案

Alibaba Android development specification, senior programmer interview questions
随机推荐
HJ4 字符串分隔
C reads data from the database and exports it to CSV
oracle安装server端
2022年ADB 命令知多少?一文2000字详细 ADB 命令大全来啦
Rotation formula of two-dimensional vector
C# UserControl造成内存泄漏
Appium mobile terminal automated testing -- building a simulator and real machine environment
HJ5 进制转换
AnatomyNet: Deep Learning for Fast and Fully Automated Whole-volume Segmentation of Head and Neck An
The idea window cannot be found in multi screen mode
Ali expert original, self-taught programming, looking for a job
Vscode failed to use SSH Remote Connection
Codeforces Round #783 (Div. 2)
718. 最长重复子数组
[编程题]汽水瓶
阿里专家原创,自学编程找工作
MSF series - Eternal Blue vulnerability
C# 从数据库读取数据, 导出到CSV
Network protocol analysis summary
DPI exception of window form dynamically created by WPF