算法提高 11-2删除重复元素
时间限制:10.0s 内存限制:256.0MB
提交此题
问题描述
为库设计新函数DelPack,删除输入字符串中所有的重复元素。不连续的重复元素也要删除。
要求写成函数,函数内部使用指针操作。
样例输入
1223445667889
样例输出
13579
样例输入
else
样例输出
ls
数据规模和约定
字符串数组最大长度为100。
这道题使用hash表就可以了
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<deque>
using namespace std;
int hash[10000];
string DelPack(string a){
string n="";
for(int i=0;i<a.length();i++){
if(hash[a[i]]==1)
hash[a[i]]=-1;
else
hash[a[i]]=1;
}
for(int i=0;i<a.length();i++){
if(hash[a[i]]==1)
n+=a[i];
}
return n;
}
int main(){
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
memset(hash,0,sizeof(hash));
string n;
cin>>n;
cout<<DelPack(n);
return 0;
}