键盘打字

输入:

7_This_is_a_test

_hs_s_a_es

输出:

7TI

说明:第一行是应该输入的文字,第二行是实际输入的文字,输出键盘中坏掉的键。

#include <iostream>    //判断哪些键坏了
#include <algorithm>
#include <cstring>
using namespace std;

const int maxn = 10001;

int main() {

	char str1[100], str2[100];
	bool hash[128] = { false }; //用来标记字符是否已被输出
	gets_s(str1);
	gets_s(str2);
	int len1 = strlen(str1);
	int len2 = strlen(str2);

	for (int i = 0; i < len1; i++)
	{
		int j;
		char c1, c2;
		for (j = 0; j < len2; j++)
		{
			c1 = str1[i];
			c2 = str2[j];
			if (c1 >= 'a' && c1 <= 'z') c1 -= 32;
			if (c2 >= 'a' && c2 <= 'z') c2 -= 32;
			if (c1 == c2) break;
		}
		if (j == len2 && hash[c1] == false)
		{
			cout << c1;
			hash[c1] = true;
		}
	} 
	return 0;
}

 

另附:第一行为已知损坏的键,第二行为本应输入的字符串,输出实际输入的。

输入格式:

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

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

输出格式:

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

7+IE. 
7_This_is_a_test.

输出样例:

_hs_s_a_tst

#include<stdio.h>
#include<string.h>
int main()
{
    int key[178]={0};//储存坏键
    int i,check=0;//check核对是否有输出
    char ch;
    while((ch=getchar())!='\n')
    {
        if(ch>='A'&&ch<='Z')
key[ch-'A'+'a']=1;//字母大小写都存入 key[ch]=1; } if(key['+'])for(i='A';i<='Z';i++)key[i]=1;//上档键坏掉,则所有大写无法打出 while((ch=getchar())!='\n') { if(key[ch])continue; printf("%c",ch); check=1; } if(check==0)
printf("\n");//如果没有输出,则输出\n }

  

 

posted @ 2018-08-05 17:52  道微真理  阅读(167)  评论(0)    收藏  举报