您的位置:首页 > 其它

1033. 旧键盘打字

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

输入格式:

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

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

输出格式:

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

注意:坏键的输入可能为空字符串,所以这里不能用scanf来读取,否则有一个case过不了。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 100000
char Change (char a);
bool Legal(char a);
int main ()
{
char wrong[N+1],first[N+1];
gets(wrong);
gets(first);
bool shift=false;
if( strchr(wrong,'+')!=0) shift=true;
int i,length=strlen(first);
if( strlen(wrong)==0)
{
printf("%s\n",first);
return 0;
}
for( i=0;i<length;i++)
{
char temp;
temp=first[i];
if (!Legal(temp)) continue;
if( shift)
{
if((temp-'A'>=0)&&(temp-'Z'<=0)) continue;
else
{
temp=Change(temp);
if( strchr(wrong,temp)==0) printf("%c",first[i]);
}
}
else
{
temp=Change(temp);
if( strchr(wrong,temp)==0) printf("%c",first[i]);
}
}
printf("\n");
system("pause");
return 0;
}
bool Legal(char a)
{
if((a-'a'>=0)&&(a-'z'<=0)) return true;
else if((a-'A'>=0)&&(a-'Z'<=0)) return true;
else if((a-'0'>=0)&&(a-'9'<=0)) return true;
else if(a-'_'==0) return true;
else if(a-','==0) return true;
else if(a-'.'==0) return true;
else if(a-'-'==0) return true;
else if(a-'+'==0) return true;
else return false;
}
char Change (char a)
{
if((a-'a'>=0)&&(a-'z'<=0)) return a-32;
else return a;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: