actually, it is to change "123456224437889" to "123456789", set a variable last, always point to the next position of a string without repeated characters, and finally set S [last] to 0, get a C string that meets the requirements
Void del_duplicated (char * s) <br/>{< br/> int n = strlen (s); <br/> If (n <= 1) <br/> return; <br/> int I, j; <br/> int last = 1; // initially, only s [0] are considered to have been processed. <br/> for (I = 1; I <n; I ++) // start from subscript 1 and then scan <br/>{< br/> for (j = 0; j <last; j ++) <br/> {<br/> If (s [I] = s [J]) // compare the uncompared characters with s [0... last-1] comparison <br/> break; // returns the same result. If a duplicate occurs, the loop is exited. <br/>}< br/> If (j = last) // This indicates that s [I] = s [J] until last-1. <br/> S [last ++] = s [I]; // Therefore S [I] is a character that has not yet appeared. Add it, and then last + 1 <br/>}< br/> S [last] = 0; // remember that the string should end with 0 <br/>}</P> <p> int main (void) <br/> {<br/> char s [] = "123456? &@? 11173289 "; <br/> del_duplicated (s); <br/> printf (" % s/n ", S); <br/> return 0; <br/>}
as you can see, if the string is composed of the same character, Every time s [I] = s [J] is set up, break is dropped, and J has never changed, all are 0, and only N comparisons are required. If all the characters are different, each last will be added with 1, the number of comparisons is 1 + 2 + 3 +... + n-1 = N (n-1)/2 times.