当前位置:网站首页>3477. Simple sorting
3477. Simple sorting
2022-07-28 15:13:00 【Pursue people far away】
Given an inclusion n Array of integers , Please delete the duplicate elements in the array and sort the array from small to large and output .
Input format
The first line contains an integer n.
The second line contains n No more than one. 1000 The positive integer .
Output format
Output the array after de duplication and sorting .
Data range
1≤n≤1000
sample input :
6
8 8 7 3 7 7
sample output :
3 7 8
set:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;
int main()
{
int n;
cin >> n;
set<int> S;
while (n--)
{
int x;
cin >> x;
S.insert(x);
}
for (auto x : S)
cout << x << ' ';
return 0;
}
use unique function :
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1010;
int q[N];
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> q[i];
sort(q, q + n);
n = unique(q, q + n) - q;
for (int i = 0; i < n; i++)
cout << q[i] << ' ';
return 0;
}
Code :
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1010;
int q[N];
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> q[i];
sort(q, q + n);
int j = 1;
for (int i = 1; i < n; i++)
if (q[i] != q[i - 1])
q[j++] = q[i];
for (int i = 0; i < j; i++)
cout << q[i] << ' ';
return 0;
}
边栏推荐
- MITK creates plug-ins and generates plug-ins
- 23、 TF coordinate transformation (III): dynamic coordinate transformation
- Namespace conflict problem
- A problem -- about dragging div in JS, when I change div to round, there will be a bug
- SSH service
- QT environment cannot run error set
- Deploy flask on Alibaba cloud server
- linear transformation
- What is the difference between UTF-8, utf-16 and UTF-32 character encoding? [graphic explanation]
- Compilation failure caused by kotlin version upgrade
猜你喜欢

35道MySQL面试必问题图解,小白都能看懂

Foundation of knowledge atlas (II) - knowledge expression system of knowledge atlas

Chapter 3 stack, queue and array

Idea2020.1.4 packages package collapse

Establishment and traversal of binary tree (implemented in C language)

2021-09-02

Introduction to mqtt protocol

Chapter II linear table

SQL labs detailed problem solving process (less1-less10)

Xiaobai can understand the 35 necessary questions in MySQL interview
随机推荐
23、 TF coordinate transformation (III): dynamic coordinate transformation
Talk about low code / zero code tools
Vtkcellpicker picking triangular patches
15、 Launch file label of ROS (I)
8、 C scope rules
3715. 最少交换次数
Knowledge map Foundation (I) - what is knowledge map
Modify the default path of Jupiter notebook
使用cpolar发布树莓派网页(apache2网页的发布)
MySQL authorization method
即刻体验 | 借助 CTS-D 进一步提升应用设备兼容性
SQL labs detailed problem solving process (less1-less10)
为什么企业需要用户自治的数字身 份
Touch hands to realize canal how to access Mysql to realize data write operation monitoring
Basic operation implementation of sequence table
QT serialization qdatastream
SQL learning
Mlx90640 infrared thermal imager sensor module development notes (VIII)
Gradle -- package multiple variants with gradle
A problem -- about dragging div in JS, when I change div to round, there will be a bug