1084 Broken Keyboard (20 分)

23 篇文章 0 订阅
10 篇文章 0 订阅

 

On a broken keyboard, some of the keys are worn out(破旧的). So when you type some sentences, the characters corresponding to those keys will not appear on screen.

Now given a string that you are supposed to type, and the string that you actually type out, please list those keys which are for sure worn out.

Input Specification:

Each input file contains one test case. For each case, the 1st line contains the original string, and the 2nd line contains the typed-out string. Each string contains no more than 80 characters which are either English letters [A-Z] (case insensitive(不区分大小写)), digital numbers [0-9], or _ (representing(相当于) the space). It is guaranteed that both strings are non-empty.

Output Specification:

For each test case, print in one line the keys that are worn out, in the order of being detected(查明). The English letters must be capitalized(大写字母). Each worn out key must be printed once only. It is guaranteed that there is at least one worn out key.

Sample Input:

7_This_is_a_test
_hs_s_a_es

Sample Output:

7TI

参考代码:

#include<cstdio>
#include<cstring>
bool hashTable[128] = {false};//用来标记字符是否已被输出
const int maxn = 100;
char str1[maxn], str2[maxn];
int main(int argc, char const *argv[])
{
  fgets(str1, maxn + 1, stdin);
  fgets(str2, maxn + 1, stdin);
  int len1 = strlen(str1) - 1;//获取长度
  int len2 = strlen(str2) - 1;

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 && hashTable[c1] == false){//第二个字符串中未出现c1,且c1位被输出过
    printf("%c", c1); 
    hashTable[c1] = true;
  }
}
printf("\n");
  return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

繁星蓝雨

如果觉得文章不错,可以请喝咖啡

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值