题意:给出两个字符串(有字母,数字和下划线_组成),第一个字符串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. 腾讯开源手游热更新方案,Unity3D下的Lua编程

    原文:http://www.sohu.com/a/123334175_355140 作者|车雄生 编辑|木环 腾讯最近在开源方面的动作不断:先是微信跨平台基础组件Mars宣布开源,腾讯手游又于近期开源 ...

  2. Load事件

    Load事件 在 窗体完全呈现之后 被 触发 如下伪代码: void  ShowWindows { .....//显示父容器 .....//显示子容器 .....//显示控件 //至此,窗体完全呈现 ...

  3. git下载别人的代码

    1. 打开别人github上的源码地址,点击Clone or download 2. 拷贝链接 3. 通过git clone URL来下载 此外,还可以通过pwd来查看当前目录的路径,一般都是下载到当 ...

  4. Java基础13:反射与注解详解

    Java基础13:反射与注解详解 什么是反射? 反射(Reflection)是Java 程序开发语言的特征之一,它允许运行中的 Java 程序获取自身的信息,并且可以操作类或对象的内部属性. Orac ...

  5. smarty语法

    HTML中直接显示数据 <{$data}> foreach循环 <{foreach from=$data item=item key=key}> <li data-ind ...

  6. 转: 更高的压缩比,更好的性能–使用ORC文件格式优化Hive

    Hive从0.11版本开始提供了ORC的文件格式,ORC文件不仅仅是一种列式文件存储格式,最重要的是有着很高的压缩比,并且对于MapReduce来说是可切分(Split)的.因此,在Hive中使用OR ...

  7. 31-THREE.JS 正方体

    <!DOCTYPE html> <html> <head> <title>Example 05.04 - Basic 2D geometries - C ...

  8. HTML——部分MP4在谷歌浏览器上无法播放

    Chrome浏览器支持HTML5,它支持原生播放部分的MP4格式(不用通过Flash等插件). 为什么是部分MP4呢?MP4有非常复杂的含义(见http://en.wikipedia.org/wiki ...

  9. python基础之多线程与多进程(一)

    并发编程? 1.为什么要有操作系统? 操作系统,位于底层硬件与应用软件之间 工作方式:向下管理硬件,向上提供接口 2.多道技术? 不断切换程序. 操作系统进程切换: 1.出现IO操作 2.固定时间 进 ...

  10. 剑指offer--33.丑数

    本来用数组做标志位,但是测试数据有第1500个,859963392,惹不起哦 ------------------------------------------------------------- ...