Delete a repeating character in a lowercase letter string in the data structure

Source: Internet
Author: User
Tags lowercase

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:



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.