1033 旧键盘打字

1033 旧键盘打字(20 分)

旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及坏掉的那些键,打出的结果文字会是怎样?

输入格式:

输入在 2 行中分别给出坏掉的那些键、以及应该输入的文字。其中对应英文字母的坏键以大写给出;每段文字是不超过 10​5​​ 个字符的串。可用的字符包括字母 [a-zA-Z]、数字 0-9、以及下划线 _(代表空格)、,.-+(代表上档键)。题目保证第 2 行输入的文字串非空。

注意:如果上档键坏掉了,那么大写的英文字母无法被打出。

输出格式:

在一行中输出能够被打出的结果文字。如果没有一个字符能被打出,则输出空行。

输入样例:

7+IE.
7_This_is_a_test.

输出样例:

_hs_s_a_tst

学了vector的erase,这题很快做出来了哈哈哈。但是翻书查了查如何接收空字符串。我发现对字符的处理是我的弱项,有时间总结一下。

参考:

#include<iostream>
#include<vector>
#include<string>
#include<cstring>
using namespace std;
int main()
{
	string  str2;
	const int kk = 100000;
	char str1[kk];
	cin.getline(str1, kk, '\n');
	cin >> str2;
	vector<char>data;
	int m = strlen(str1);
	int n = str2.size();
	int dax = 1;
	for (int i = 0; i < n; i++)
		{
			data.push_back(str2[i]);
		}
   if(m!=0)
     {
		for (int i = 0; i < m; i++)
		{
			if (str1[i] == '+')
				dax = 0;
			for (int j = 0; j < data.size(); j++)
			{
				if (tolower(str1[i]) == tolower(data[j]))
				{
					data.erase(data.begin() + j);
					j--;
				}
			}
		}
		if (data.empty())
			cout << endl;
		else
		{
			for (int i = 0; i < data.size(); i++)
			{
				if (dax == 0 && (data[i] >= 'A'&&data[i] <= 'Z'))
					continue;
				else
					cout << data[i];
			}
		}
	}
	else
		for (int i = 0; i < data.size(); i++)
		{
				cout << data[i];
		}
	system("pause");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/wss123wsj/article/details/82054938