题意:给出两个字符串(有字母,数字和下划线_组成),第一个字符串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. Treflection03_getFields_getField

    1. package reflectionZ; import java.lang.reflect.Constructor; import java.lang.reflect.Field; public ...

  2. Android两个Activity之间的数据交换

    1. 不带数据 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceS ...

  3. 【scala】构造器

    和Java或C++一样,Scala可以有任意多的构造器. 不过Scala类有一个构造器比其他所有构造器都更为重要,它就是主构造器. 除了主构造器之外,类还可以有任意多的辅助构造器. 主构造器 在Sca ...

  4. Prism开发人员指南5-WPF开发 文档翻译(纯汉语版)

    2014四月       Prism以示例和文档的形式帮助你更简单的设计丰富灵活易维护的WPF程序.其中使用的设计模式体现了一些重要的设计原则,例如分离关注点和松耦合,Prism帮助你利用松耦合组件设 ...

  5. DTO数据传输对象

    如果有多个对象需要传输到页面上需要用DTO传输

  6. 2017.11.24 Stm8L151-factory

    Marking---------factory fun... /** ***************************************************************** ...

  7. 转一篇pgpool配置

    转一篇pgpool配置 http://dz.sdut.edu.cn/blog/subaochen/2013/08/postgresql-9-1的failover配置及其管理/ 环境介绍 在两台虚拟机上 ...

  8. 有效处理Java异常三原则

    Java中异常提供了一种识别及响应错误情况的一致性机制,有效地异常处理能使程序更加健壮.易于调试.异常之所以是一种强大的调试手段,在于其回答了以下三个问题: 什么出了错? 在哪出的错? 为什么出错? ...

  9. Java中BIO,NIO,AIO的理解

    在高性能的IO体系设计中,有几个名词概念常常会使我们感到迷惑不解.具体如下: 1 什么是同步? 2 什么是异步? 3 什么是阻塞? 4 什么是非阻塞? 5 什么是同步阻塞? 6 什么是同步非阻塞? 7 ...

  10. 在Blender上安装RenderMan插件

    2018/3/27 Download and Install Blender itself Download RenderMan Installer (Need to register an acco ...