输入一个字符串,找到相同的字符,将后面出现的字符删除,不改变字符串的顺序。
例如:
Hello -》Helo
人山人海 -》人山海
代码实现:
#include <iostream>
#include<string>
using namespace std;
int main ()
{
string str="hello world";//这里自己设置输入信息
for(int i=0;i<str.length();i++)
for(int j=i+1;j<str.length();j++)
{
if(str[i]==str[j])
str[j]=NULL;
}
for(int j=0;j<str.length();j++)
{
if(str[j]==NULL)
continue;
else cout<<str[j];
}
return 0;
}