The algorithm is designed and the code is written out to remove the repeated characters in the string, and no additional cache space is used.
Note: The ability to use an additional one or two variables, but does not agree to open an additional array copy.
Simple question directly on the code:
#include <stdio.h> #include <string.h>void remove_duplicate (char vstr[]) {int Len = strlen (VSTR); Len) {printf ("The string is Null\n"); return;} int Count = 0;for (int i=0; i<len; ++i) {if (vstr[i]! = ' + ') {vstr[count++] = vstr[i];for (int k=i+1; k<len; ++k) {if (Vstr[i] = = Vstr[k]) {vstr[k] = '% ';}}}} Vstr[count] = ' + ';} void Remove_duplicate2 (char vstr[]) {int Len = strlen (VSTR); Len) {printf ("The string is Null\n"); return;} BOOL Visited[256];memset (visited, 0, sizeof (visited)), int Count = 0;for (int i=0; i<len; ++i) {if (! Visited[vstr[i]]) {vstr[count++] = Vstr[i]; Visited[vstr[i]] = true;}} Vstr[count] = ' + ';} void Test () {char str[] = "13434343435568889HHHHHHHFDCVBB"; remove_duplicate (str);p rintf ("%s\n", str);}
Keep it up those write several algorithms per week, entertainment!
Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.
004 String weight (keep it up)