牛客网PAT乙级真题 旧键盘 (20)

牛客网PAT乙级真题 旧键盘 (20)

时间限制 1000 ms 内存限制 32768 KB 代码长度限制 100 KB 判断程序 Standard (来自 小小)
题目描述
旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及实际被输入的文字,请你列出
肯定坏掉的那些键。

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

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

输入例子:
7_This_is_a_test
_hs_s_a_es

输出例子:
7TI

#include<stdio.h>
#include<string.h>
using namespace std;
//字符串比较啊
int main()
{
    char s1[81],s2[81],s3[81];
    int i,j,k,cou;
    scanf("%s%s",s1,s2);
    i=j=k=0;
    while(i<strlen(s1))
    {
        if(s1[i]==s2[j])
            j++;
        else
        {
            char temp;
            if(s1[i]>='a' && s1[i]<='z')
                temp=s1[i]-'a'+'A';
            else temp=s1[i];
            for(cou=0;cou<k;cou++)if(s3[cou]==temp)break;//判重的功能,复杂度有点高啊
            if(cou==k)s3[k++]=temp;
        }
        i++;
    }
    for(cou=0;cou<k;cou++)printf("%c",s3[cou]);
    printf("\n");
    return 0;
}

发布了18 篇原创文章 · 获赞 2 · 访问量 223

猜你喜欢

转载自blog.csdn.net/zhou_hao_ran/article/details/103773163