OpenJudge exercises and answers (C ++) -- question 4085: array deduplication
Question:
-
Total time limit:
-
1000 ms
-
Memory limit:
-
1000kB
-
Description
-
Mr. Xiaoji is a bank accountant who encountered some problems when handling bank accounts. There are a series of integers that contain repeated integers. You need to remove the duplicates and sort the output. Can you help Xiaoji solve the problem?
-
Input
-
There are two rows of input data, n for the first row and n for the second row. There may be duplicates between integers and several spaces between integers.
N <= 105, All integers do not exceed 104.
-
Output
-
The output value is one row, which is the order of n numbers from small to large.
-
Sample input:
-
34 4 2
-
Sample output:
-
2 4
Solution:
# Include <iostream> using namespace std; void Qsort (int a [], int low, int high) {if (low> = high) {return;} int first = low; int last = high; int key = a [first];/* use the first record of the word table as the pivot */while (first <last) {while (first <last & a [last]> = key) {-- last;} a [first] = a [last]; /* Move smaller than the first one to the lower end */while (first <last & a [first] <= key) {++ first ;} a [last] = a [first];/* move bigger than the first one to the high end */} a [first] = key;/* pivot records in place */Qsort (, low, first-1); Qsort (a, first + 1, high);} int main () {int n; cin> n; int a [n]; for (int I = 0; I <n; I & #43; & #43;) cin = ""> a [I] ;} Qsort (a, 0, n-1); cout <a [0] <"int =" "I =" 1; I <n; I ++) "return =" "pre =" "> <p> </a [0] <"> </n; I & #43; & amp; #43;)> </iostream>