OpenJudge exercises and answers (C ++) -- question 4085: array deduplication

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.