1029. 旧键盘(20)

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
using namespace std;

struct node
{
	string name;
	string date;
};
int main()
{
	freopen("d://1.txt", "r", stdin);
	freopen("d://2.txt", "w", stdout);
	string  n, m;
	while (cin >> n >> m)
	{
		for (int i = 0; i < n.length(); i++)
		{
			if (n[i] >= 'a'&&n[i] <= 'z')
			{
				n[i] = n[i] - 'a' + 'A';
			}
		}
		for (int i = 0; i < m.length(); i++)
		{
			if (m[i] >= 'a'&&m[i] <= 'z')
			{
				m[i] = m[i] - 'a' + 'A';
			}
		}
		vector<char> temp;
		set<char> dis;
		for (int i = 0, j = 0; i < n.length();)
		{
			if (n[i] != m[j])//之前把两个条件放在一起&&了。结果出错。因为存在不等但是已添加的,指针状态会出错
			{
				if (dis.count(n[i]) == 0)
				{
					temp.push_back(n[i]);
					dis.insert(n[i]);
				};
				i++;
			}
			else
			{
				i++;
				j++;
			}
		}
		for (int i = 0; i < temp.size(); i++)
		{
			cout << temp[i];
		}

	}
	return 0;
}

你可能感兴趣的:(1029. 旧键盘(20))