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

题目:

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

输入格式:

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

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

输出格式:

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

输入样例:

7+IE.
7_This_is_a_test.

输出样例:

_hs_s_a_tst

   这题之前写了,再次做时用的是char 字符串测试点4超时了,但是使用string处理就不会出现这样的问题。

一:超时代码

#include 
#include 
#include 
using namespace std;
const int N=100001;
int main()
{
     char str1[N],str2[N];
     bool hashtable[256]={false};
     cin.getline(str1,N);
     cin.getline(str2,N);
     for(int i=0;i='A'&&str1[i]<='Z')
          {
               hashtable[str1[i]+32]=true;
          }
     }
     for(int i=0;i='A'&&str2[i]<='Z')
          {
               if(hashtable[str2[i]]==false&&hashtable['+']==false)           printf("%c",str2[i]);
          }
          else
          {
               if(hashtable[str2[i]]==false) printf("%c",str2[i]);
          }
     }

     return 0;
}

 

二:使用string

#include 
#include 
#include 
using namespace std;
bool hashtable[256]={false};
int main()
{
	int num=0;
    string a,b;
	getline(cin,a);
	getline(cin,b);
	for(int i=0;i='A'&&a[i]<='Z') hashtable[a[i]+32]=true;
	}
	for(int i=0;i='A'&&b[i]<='Z')
		{
			if(hashtable[b[i]]==false&&hashtable['+']==false) 
			{
				cout<

 

 

 

你可能感兴趣的:(PAT乙级,C,散列)