1029 旧键盘

#include<iostream>
#include<algorithm>
#include <vector>
#include <string>
using namespace std;
int main()
{
	string str1;
	string str2;
	cin >> str1 >> str2;
	int t = 0;
	string bad;
	for (int i = 0; i < str1.size(); i++)
	{
		if (str1[i] == str2[t])
		{
			t++;
		}
		else
			bad += str1[i];
	}
	for (int j = 0; j < bad.length(); j++)
		cout << bad[j] << " ";
	cout << endl;
	string zhuanhua;
	for (int j = 0; j < bad.length(); j++)
	{
		char daxie;
		if (bad[j] <= 122 && bad[j] >= 97)
		{
			daxie = bad[j] - 32;
			zhuanhua += daxie;
		}
		else
			zhuanhua += bad[j];
	}
	/*for (int j = 0; j < zhuanhua.length(); j++)
		cout << zhuanhua[j] << " ";*/
	/*cout << endl;*/
	int rr = 0;
	bool tag[256] = { false };
	int i = 0;
	int j = 0;
	while (zhuanhua[i] != '\0')
	{
		if (!tag[zhuanhua[i]])
		{
			cout << zhuanhua[i];
			tag[zhuanhua[i]] = true;
			/*zhuanhua[j++] = zhuanhua[i];*/
		}
		i++;
	}
	/*zhuanhua[j] = '\0';*/
	for (int rr = 0; rr < zhuanhua.length(); rr++)
		cout << zhuanhua[rr] << endl;
}


这里解决了:如何在string中删除重复的字符
这里采用的方法是以空间换时间
需要注意的是:string字符串并不是以\0作为结束标志,它仅仅只是个空字符!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值