Analyze the problem:
Delete the duplicate characters in a lowercase letter string, for example: AABCDEEC, deleting duplicate words specifier: ABCDE
The method used in this problem is: Define I=0 and two subscript J, K, start to point to the second A, when a[k] is not equal to a[i], K subscript for + +;
When A[k]=a[i], the value of A[k] will be assigned to A[J], and then proceed back, until the value of a[k] is equal to "", the value of A[j] is assigned to ' "".
The same string is deleted.
The implementation of the Code:
#include <iostream>
using namespace std;
void Deletecommonstr (char a[])
{
int i = 0;
while (a[i]! = ' + ')
{
Int j = i + 1;
int k = i + 1;
while (a[k]! = ' + ')
{
if (a[k]! = A[i])
{
a[j] = a[k];
++j;
++k;
}
else
{
++k;
}
}
A[J] = ' + ';
++i;
}
}
int main ()
{
char a[100];
Gets (a);
Deletecommonstr (a);
cout << "Delete the same string after:" <<a << Endl;
System ("pause");
return 0;
}
Results of the operation: