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

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1293 1293 球与切换器 题目来源: Codility 基准时间限制: ...

  2. 条款19:定义class就相当于定义一个个的内置类型

    下面的条框应该是谨记的: 1. 新的type应该如何创建与销毁 2. 对象的初始化与赋值应该有什么样的区别 3. 新type的对象如果被pass-by-value,有什么影响? 4. 什么事新type ...

  3. Arcgis for Js之GeometryService实现测量距离和面积

    距离和面积的测量时GIS常见的功能,在本节,讲述的是通过GeometryService实现测量面积和距离.先看看实现后的效果:                                  距离 ...

  4. Win7系统64位环境下使用Apache——Apache2.4整合Tomcat与mod_jk

    转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/70398091 本文出自[我是干勾鱼的博客] 之前的几篇文章: Win7系统64位 ...

  5. 列表(增删改查)元组tupe

    增加:有三种,append:在后面添加.Insert按照索引添加,expend:迭代着添加.#append li = ['lishi','alex','lili'] li.append(') prin ...

  6. 解决Chrome关联HTML文件,图标不显示的问题。

    解决Chrome关联HTML文件,图标不显示的问题. 一.方法一 1.win+r,输入regedit,调出注册表信息,按下Ctrl+F,在注册表里搜索.在注册表里新建几个文件就可以了 a.新建Old ...

  7. bzoj 1725 Corn Fields

    Written with StackEdit. Description Farmer John新买了一块长方形的牧场,这块牧场被划分成M列N行\((1<=M<=12; 1<=N< ...

  8. thunderbird 设置 邮件回复时内容在上方显示

    1 . 编辑->属性 2.选择当前账户,在弹出窗体的右下角 选择 管理标示 ,在弹出窗中选择编辑 3.在弹出标识设置窗体中选择 编写&地址簿 选项卡选择 在引用内容之前回复

  9. npm 私服工具verdaccio 安装配置试用

      1. 安装 npm install -g verdaccio 2. 启动 verdaccio // 界面显示信息 Verdaccio doesn't need superuser privileg ...

  10. python 无序模块,hashlib模块

    无序模块什么是无序模块,将字符串转化为十六进制的字符串类型,主要运用在网络编程中.1,json模块 1,用于网络传输,跨语言,可用的类型有 int str 列表-->元祖会变为列表 字典--&g ...