PAT 1019

题目描述

旧键盘上坏了几个键,

于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及实际被输入的文字,请你列出

肯定坏掉的那些键。

输入描述:

输入在2行中分别给出应该输入的文字、以及实际被输入的文字。每段文字是不超过80个字符的串,由字母A-Z(包括大、小写)、数字0-9、

以及下划线“_”(代表空格)组成。题目保证2个字符串均非空。


输出描述:

按照发现顺序,在一行中输出坏掉的键。其中英文字母只输出大写,每个坏键只输出一次。题目保证至少有1个坏键。

输入例子:

7_This_is_a_test

_hs_s_a_es

输出例子:

7TI

#include <stdio.h>
#include <string.h>
#include <ctype.h>

int jude_exist(char targ,char input[],int num)
{
	int i;
    int f1 = 1;
    int f2 = 0;
	//判断是否是小写
	if(islower(targ))	targ= toupper(targ);

	for(i = 0;i < num;i++)
	{
		if(targ == input[i])
			return f1;
	}
	return f2;
}

int main(void)
{
	char target[1000];
	char input[1000];
	//char target[1000] = "faengebhe4brhbrrkbhakbnrkbhrbhrkbhr";
	//char input[1000] = "fng4n";
	char output[100];
	int count = 0;
	int i,j,len1,len2;
	int flag = 1;//为了第一次也被甄别出来

	gets(target);
	gets(input);
	len1 = strlen(target);
	len2 = strlen(input);
	for(i = 0;i < len1;i++)
	{
		for(j = 0;j < len2;j++)
		{
			if(target[i] == input[j])
			{
				break;
			}
			else
			{
				if(j== len2-1)//对比结束
				{
					//判断元素是否已经被标记为缺少,是则停止查找,判断下一个
					if(i>0 && !jude_exist(target[i],output,count)) flag = 1;
					if(flag == 1)		
					{
						flag = 0;
						if(islower(target[i]))
						{
							
							output[count] = toupper(target[i]);
							printf("%c",output[count]);
							count++;
						}
						else
						{
							output[count] = target[i];
							printf("%c",output[count]);
							count++;
						}
					}	
				}
			}
		}
	}
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值