码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 【PAT甲级】1084 Broken Keyboard


    ✍个人博客:https://blog.csdn.net/Newin2020?spm=1011.2415.3001.5343
    📚专栏地址:PAT题解集合
    📝原题地址:题目详情 - 1084 Broken Keyboard (pintia.cn)
    🔑中文翻译:坏掉的键盘
    📣专栏定位:为想考甲级PAT的小伙伴整理常考算法题解,祝大家都能取得满分!
    ❤️如果有收获的话,欢迎点赞👍收藏📁,您的支持就是我创作的最大动力💪

    1084 Broken Keyboard

    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
    
    • 1
    • 2

    Sample Output:

    7TI
    
    • 1
    思路
    1. 输入两个字符串 a 和 b ,并且在 b 后面加上 # 作为终止标志。
    2. 设置两个指针,i 负责遍历字符串 a ,j 负责遍历字符串 b 。
    3. 每次遍历时如果遇到小写字母,统一变成大写字母,这里用到了库函数 toupper ,能够将小写字母转换成大写字母并返回。这样,就得到了两个字符 x 和 y 。
    4. 如果 x==y ,则 i 和 j 都往后移一位。
    5. 如果 x!=y ,则说明键盘上 x 的地方坏了,如果还没有输出 x 则输出它,然后只有 i 往后移一位。
    代码
    #include
    using namespace std;
    
    int main()
    {
        string a, b;
        cin >> a >> b;
    
        bool st[200] = { 0 };
        b += '#'; //作为终止标志
        for (int i = 0, j = 0; i <= a.size(); i++)
        {
            char x = toupper(a[i]), y = toupper(b[j]);
            if (x == y)    j++;
            else
            {
                if (!st[x])  cout << x, st[x] = true;
            }
        }
    
        return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
  • 相关阅读:
    ios ipa包上传需要什么工具
    二维码怎么做列表?点击可跳转其他内容
    大数据随记 —— RDD 的创建
    为什么哈希加密后还要加盐?
    Pytest用例自定义 - 重复、并行、串行
    java计算机毕业设计校内图书馆智能管理系统源码+系统+数据库+lw文档+mybatis+运行部署
    django中事务和锁
    字节面试遇到的一个超级复杂的输出题,前端人必看系列,搞定之后再也没有输出题可以难倒你
    2.6 Go语言中的Map
    基于FPGA的VGA协议实现
  • 原文地址:https://blog.csdn.net/Newin2020/article/details/126653112
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号