题意:给出两个字符串(有字母,数字和下划线_组成),第一个字符串str1是由键盘输入的字符串,第二个字符串str2是屏幕显示的字符串,问键盘有哪几个按键坏了,根据输入的顺序,输出坏掉的键(仅输出一次)。要求输出字母为大写。

 思路:
1、因为不区分大小写且要求输出为大写,因此,对输入的字符均先统一转换成大写,可以用toupper(char ch)函数,在头文件<ctype.h>下面
2、定义bool goodKeys[128],初始化为false。先遍历str2,标记出现过的字符为true;然后遍历str1,若某个字符为false,说明这个字符没有出现过,也就是坏掉了,于是把这个字符输出,因为坏掉的键只需要输出一次即可,因此输出一次后就立即标记为true。

代码:

#include <cstdio>
#include <cstring>
#include <ctype.h>

int main()
{
    ], str2[];
    ]={false};//goodKeys[ch]为true表示字符ch为完好的键
    scanf("%s",str1);
    scanf("%s",str2);
    int len=strlen(str2);
    ;i<len;i++){
        str2[i]=toupper(str2[i]);//小写转大写
        goodKeys[str2[i]]=true;
    }
    len=strlen(str1);
    ;i<len;i++){
        str1[i]=toupper(str1[i]);
        if(goodKeys[str1[i]]==false) {
            goodKeys[str1[i]]=true;
            printf("%c",str1[i]);
        }
    }
    ;
}

1084 Broken Keyboard的更多相关文章

  1. PAT 1084 Broken Keyboard

    1084 Broken Keyboard (20 分)   On a broken keyboard, some of the keys are worn out. So when you type ...

  2. 1084 Broken Keyboard (20 分)

    1084 Broken Keyboard (20 分) On a broken keyboard, some of the keys are worn out. So when you type so ...

  3. PAT 1084 Broken Keyboard[比较]

    1084 Broken Keyboard (20 分) On a broken keyboard, some of the keys are worn out. So when you type so ...

  4. 1084. Broken Keyboard (20)【字符串操作】——PAT (Advanced Level) Practise

    题目信息 1084. Broken Keyboard (20) 时间限制200 ms 内存限制65536 kB 代码长度限制16000 B On a broken keyboard, some of ...

  5. pat 1084 Broken Keyboard(20 分)

    1084 Broken Keyboard(20 分) On a broken keyboard, some of the keys are worn out. So when you type som ...

  6. 1084. Broken Keyboard (20)

    On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters ...

  7. PAT Advanced 1084 Broken Keyboard (20) [Hash散列]

    题目 On a broken keyboard, some of the keys are worn out. So when you type some sentences, the charact ...

  8. PAT (Advanced Level) 1084. Broken Keyboard (20)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  9. 1084. Broken Keyboard (20)-水题

    #include <iostream> #include <cstdio> #include <string.h> #include <algorithm&g ...

随机推荐

  1. Spring中Bean的生命周期是怎样的

    1.Spring对Bean进行实例化(相当于程序中的new Xx()) 2.Spring将值和Bean的引用注入进Bean对应的属性中 3.如果Bean实现了BeanNameAware接口,Sprin ...

  2. 判断浏览器是否支持某一个CSS3属性

    判断浏览器是否支持某一个CSS3属性 function supportCss3(style) { var prefix = ['webkit', 'Moz', 'ms', 'o'], i, humpS ...

  3. SQL正则表达式

    (转自:http://blog.csdn.net/xu1314/article/details/10174067) 当我们要进行一些简单的糊涂查询时用百分号(%),通配符(_)就可以了.其中%表达任意 ...

  4. shell编程学习1

    1.shell是操作系统的终端命令行 (1)shell可以理解为软件系统提供给用户操作的命令行界面,可以说它是人机交互的一种方式.    (2)我们可以使用shell和操作系统.uboot等软件系统进 ...

  5. Struts04---命名空间的查询顺序以及默认执行的Action

    01.创建login.jsp <%@ page language="java" import="java.util.*" pageEncoding=&qu ...

  6. WMS专业名词解释

    1.摘果:按照单一客户上订单的内容进行拣选货品(即去货位上拣货),拣选完成后即可直接进行质检.包装. 2.播种:将多个客户订单上的货品进行汇总,然后对这些货品进行拣选.拣选完成后,再区分出每一个客户的 ...

  7. 事件穿透父层 直达子层 pointer-events:none

    之前我也做过一些canvas特效,往往在canvas全屏时,canvas下层的div就无法进行dom的事件操作,点击之类的就失灵了.之前我的做法要么就是在canvas上加入点击事件,穿透到下层,或者把 ...

  8. what is out of band mode.

    Most of the steps are the same, except instead of sending an URL as the oauth_callback to request_to ...

  9. Unity3d 背景、音效 播放 简单demo

    仅实现功能,AudioListener在MainCamera中 using UnityEngine; using System.Collections; using System.Collection ...

  10. hexo多主题切换

    今天看到一个朋友在github上面的issue 大概问题就是怎么在不同的电脑上面使用 git有个这么个东西Submoudle中文叫做子模块 具体使用教程看这里Git-工具-子模块 这里只说怎么搞hex ...