PAT乙级1033旧键盘打字 20(分)

题目

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

输入格式:

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

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

输出格式:

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

输入样例:

7+IE.
7_This_is_a_test.

输出样例:

_hs_s_a_tst

代码


#include<iostream>
using namespace std;
int main()
{
    
    
	string can = "abcdefghijklmnopqrstuvwxyz#ABCDEFGHIJKLMNOPQRSTUVWXYZ#0123456789_,.-+";
	char input;
	int index;
	while (1)
	{
    
    
		input = getchar();
		if (input == '\n')
			break;
		index = can.find(input, 0);
		if (input >= 'a' && input <= 'z')
		{
    
    
			if(index!=-1)
				can = can.substr(0, index) + can.substr(index + 1);
			input -= 32;
			index = can.find(input, 0);
			if (index != -1)
				can = can.substr(0, index) + can.substr(index + 1);
		}
		else if (input >= 'A' && input <= 'Z')
		{
    
    
			if (index != -1)
				can = can.substr(0, index) + can.substr(index + 1);
			input += 32;
			index = can.find(input, 0);
			if (index != -1)
				can = can.substr(0, index) + can.substr(index + 1);
		}
		else if (input == '+')
		{
    
    
			if (index != -1)
				can = can.substr(0, index) + can.substr(index + 1);
			index = can.find('#', 0);
			if (index != -1&& can.find('#', index + 1)!=-1)
				can = can.substr(0, index) + can.substr(can.find('#',index+1)+1);
		}
		else
		{
    
    
			if (index != -1)
				can = can.substr(0, index) + can.substr(index + 1); 
		}
	}
	while (1)
	{
    
    
		input = getchar();
		if (input == '\n')
			break;
		if (can.find(input, 0) != -1)
			cout << input;
	}
	return 0;
}

题目详情链接

猜你喜欢

转载自blog.csdn.net/qq_41985293/article/details/115035275
今日推荐