zoukankan      html  css  js  c++  java
  • PAT (Basic Level) Practice 1029 旧键盘 (20分) (string 中的find查找用法)

    1.题目

    旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及实际被输入的文字,请你列出肯定坏掉的那些键。

    输入格式:

    输入在 2 行中分别给出应该输入的文字、以及实际被输入的文字。每段文字是不超过 80 个字符的串,由字母 A-Z(包括大、小写)、数字 0-9、以及下划线 _(代表空格)组成。题目保证 2 个字符串均非空。

    输出格式:

    按照发现顺序,在一行中输出坏掉的键。其中英文字母只输出大写,每个坏键只输出一次。题目保证至少有 1 个坏键。

    输入样例:

    7_This_is_a_test
    _hs_s_a_es
    

    输出样例:

    7TI

    2.题目分析

    使用string的find函数,未找到返回值为string::npos,需要头文件#include<cctype>

     3.代码

    #include<iostream>
    #include<string>
    #include<cstring>
    #include<cctype>
    using namespace std;
    int main()
    {
    	string a, b,answer;
    	cin >>a >>b;
    	for (int i = 0; i < a.length(); i++)
    	{
    		if (b.find(a[i]) == string::npos&&answer.find(toupper(a[i]))== string::npos)
    		{
    			answer += toupper(a[i]);
    
    		}
    	}
    	cout << answer;
    
    }
    
  • 相关阅读:
    vertical-align
    剑指offer刷题
    ES6 promise
    wangyi准备
    spring定时器
    xshell下linux常用操作
    HSSFWorkbook生成excel文件
    梳理并分解继承体系
    JSON格式数据转换
    部署项目
  • 原文地址:https://www.cnblogs.com/Jason66661010/p/12788962.html
Copyright © 2011-2022 走看看