码迷,mamicode.com
首页 > 其他好文 > 详细

1029 旧键盘 (20 分)

时间:2019-02-20 12:54:12      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:++   中英文   res   amp   erase   stream   英文   ack   algo   

1029 旧键盘 (20 分)

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

输入格式:

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

输出格式:

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

输入样例:

7_This_is_a_test
_hs_s_a_es

输出样例:

7TI
#include<iostream>
#include<string>
#include<vector>
#include<string>
#include<cstdio>
#include<cmath>
#include<string.h>
#include<algorithm>
#include<unordered_map>
#include<stack>
using namespace std;


int main()
{
    string str1,str2;
    cin>>str1>>str2;
    unordered_map<char,int>res;
    for(int i=0,j=0;i<str1.size();i++)
    {

        if(str1[i]==str2[j])
            j++;
        else
        {
            if(isalpha(str1[i]))
                str1[i]=toupper(str1[i]);
            res[str1[i]]++;
        }
    }
    for(int i=0;i<str1.size()&&!res.empty();i++)
    {
        if(res[str1[i]]!=0)
        {
            cout<<str1[i];
            res.erase(str1[i]);
        }

    }
    return 0;
}

 


  

1029 旧键盘 (20 分)

标签:++   中英文   res   amp   erase   stream   英文   ack   algo   

原文地址:https://www.cnblogs.com/zhanghaijie/p/10405575.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!