算法提高 11-2删除重复元素

算法提高 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; 
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值