Hrbust-1545-Basic Data Structure-sequence table (2)

Source: Internet
Author: User

Http://acm.hrbust.edu.cn/index.php? M = problemset & A = showproblem & problem_id = 1545.

Basic Data Structure-sequence table (2)
Time Limit: 1000 MS Memory limit: 10240 K
Total submit: 412 (165 Users) Total accepted: 188 (150 Users) Rating: Special Judge: No
Description

In an ordered table with a length of n (n <1000), there may be "redundant" data elements with the same value (type: integer ), write a program to delete "redundant" data elements from the ordered table, so that the table is composed of a "non-pure table" (elements with the same value may have multiple) to a "Pure table" (only one element with the same value can exist in the table ).

Input

The length of the input table in the first row is N;

In the second row, enter the N element values initially stored in the sequence table.

Output

The number of elements in the sequence table after the redundant elements are deleted in the first row;

The second row outputs the sequence table elements after deletion.

Sample Input

12

5 2 5 3 3 4 2 5 7 5 4 3

Sample output

5

5 2 3 4 7

Solution: Use a flag array to mark whether the current number has appeared after it

# Include <stdio. h>

Int A [1010];
Int flag [1010];
Int ans [1010];

Int main (){
Int N, I, j;
While (scanf ("% d", & N )! = EOF ){
For (I = 0; I <n; I ++ ){
Scanf ("% d", & A [I]);
Flag [I] = 0;
}
For (I = 0; I <n-1; I ++ ){
For (j = I + 1; j <n; j ++ ){
If (A [I] = A [J]) {
Flag [J] = 1;
}
}
}
For (I = J = 0; I <n; I ++ ){
If (flag [I] = 0 ){
Ans [J] = A [I];
J ++;
}
}
Printf ("% d \ n", J );
For (I = 0; I <j-1; I ++ ){
Printf ("% d", ANS [I]);
}
Printf ("% d \ n", ANS [I]);
}
Return 0;
} View code

Hrbust-1545-Basic Data Structure-sequence table (2)

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.