C language · Delete duplicate elements

Source: Internet
Author: User

Algorithm increase 11-2 Delete repeating element time limit: 10.0s memory limit: 256.0MBThe problem is described as the library design new function Delpack, which deletes all the repeating elements in the input string. Discontinuous repeating elements are also removed.
A function is required, and a pointer operation is used inside the function. Sample input 1223445667889 Sample output 13579 sample input else sample output LS data size and convention string array maximum length is 100.
1 /*2 Ideas:3 The string is stored in the character array A, and the value is copied to array B, and each element of B is traversed4 The corresponding element in B is set to-1, compared to each element in a. 5 An element in output B that is not-1. 6 */ 7#include <stdio.h>8#include <string.h>9 Chara[ -],b[ -];Ten voidDel (intIndexintLen) { One      for(intI=0; i<len;i++){ A         if(index = = i)Continue;//Subscript is the same as the same element does not compare, into the next loop -         if(B[index] = = A[i]) b[index]=-1;//have the same element with a value of-1 -     } the } - intMain () { - gets (a); -memcpy (B,a,sizeof(a));//Copy the elements of A to B +     intLen=strlen (a);//find the length of a -      for(intI=0; i<len;i++){ + Del (I,len); A     } at      for(intI=0; i<len;i++) {//elements of non-1 in output B -         if(b[i]!=-1){ -printf"%c", B[i]); -         } -     } -     return 0; in}

C language · Delete duplicate elements

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.