Sequential Table Application 2: Redundant element deletion of the table-building algorithm

Source: Internet
Author: User

Sequential Table Application 2: Redundant element deletion of the table-building algorithmTime limit:3 Ms Memory limit:600 KiB Problem description A sequential table of no more than 10000 data, there may be some "redundant" data elements with the same value (type Integer), and a program removes "redundant" data elements from the order table, making the table a "non-pure table" (an element with the same value may have more than one in the table) becomes a "pure table" (the element with the same value retains only the first one in the table).
Requirements:
1, must first define the linear table structure and the operation function, in the main function with this definition and the Operation function call realizes the problem function;
2, the object of the subject is familiar with the order table in the original table space based on the new table algorithm, in order to complete the original table space on the basis of the completion of the deletion, the process of building a table must not open up new table space;
3. Do not use the original TABLE element to remove the way. Input the first line to enter an integer n, representing the following n lines of input;
After entering n rows, each line enters an integer m, followed by the M data, representing each element of the corresponding sequential table. Output has n rows, and the result of removing extra elements for each sequential table is the sample Input
45 6 9 6 8 93 5 5 55 9 8 7 6 510 1 2 3 4 5 5 4 2 1 3
Sample Output
6 9 859 8 7 6 51 2 3 4 5


Tip: The main subject is to create a sequential table when the operation to achieve the data in the table updates, can be traversed to find duplicate elements, and the sequential table is shortened, gradually set up to achieve the deletion of many and elements.

The code is implemented as follows (GCC):
#include <stdio.h>#include<stdlib.h>typedefstructnode{intdata[10005]; intLast ;} ST; ST*creatdelete (ST *head) {    intI, J; scanf ("%d", &head-data[0]);  for(i =1; I < head, last; i++) {scanf ("%d", &headData[i]);  for(j =0; J < I; J + +)        {            if(Head-data[i] = = HeadData[j]) {i--; HeadLast = head, last-1; }        }    }    returnhead;}intMain () {ST*Head; intN, I; scanf ("%d", &N);  while(n--) {Head= (ST *)malloc(sizeof(ST)); scanf ("%d", &headLast ); Head=Creatdelete (head);  for(i =0; I < head, last; i++) {printf ("%d", head->Data[i]); if(I! = head, last-1) printf (" "); Elseprintf"\ n"); }    }    return 0;}/***************************************************result:acceptedtake Time:4mstake memory:156kb************* ***************************************/

Sequential Table Application 2: Redundant element deletion of the table-building algorithm

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.