PAT乙级 1033 旧键盘打字

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

输入格式:

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

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

输出格式:

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

输入样例:

7+IE.
7_This_is_a_test.

输出样例:

_hs_s_a_tst

代码:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#define INIT_SIZE 100
#define INCREMENT 100 
typedef struct{
	char key,sign;
}input_char; 
typedef struct{
	input_char *elem;
	int length,listsize;
}inputstring;
int main(){
	input_char *newbase; 
	inputstring L;
	L.elem=(input_char *)malloc(INIT_SIZE*sizeof(input_char));
	L.listsize=INIT_SIZE;
	L.length=0;
	
	char broken_key[68];
	gets(broken_key);
	
	int i=0;
	char ch;
	while((ch=getchar())!='\n'){
		if(L.length>=L.listsize){
			newbase= (input_char *)realloc(L.elem,(L.listsize+INCREMENT)*sizeof(input_char));
			L.elem=newbase;
			L.listsize+=INCREMENT;
		}
		L.elem[i].key=ch;
		L.elem[i++].sign=1;
		++L.length; 
	}
	
	int strlen_string=i;
	int shift_sign=1;
	for(i=0;i<strlen(broken_key);++i){
		if(broken_key[i]=='+'){
			shift_sign=0;
			continue;
		}
		for(int j=0;j<strlen_string;++j){
			if(broken_key[i]==toupper(L.elem[j].key)){
				L.elem[j].sign=0;
			}
		}
	}
	for(i=0;i<strlen_string;i++){
		if(L.elem[i].sign==1){
			if(shift_sign==0&&L.elem[i].key>='A'&&L.elem[i].key<='Z'){
				continue; 
			}
			else{
				printf("%c",L.elem[i].key);
			}
		}
	}
	return 0;
}

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_37205425/article/details/83830114