• pat 1084. Broken Keyboard (20)


    1084. Broken Keyboard (20)

    时间限制
    200 ms
    内存限制
    65536 kB
    代码长度限制
    16000 B
    判题程序
    Standard
    作者
    CHEN, Yue

    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
    
    Sample Output:
    7TI

    解:常规思路,两层循环,为了使结果不重复,将未出现的值添加到第二个字符串中,比如说7在第二行字符串s2中没有出现,我们将7加到s2中,这样在下次遍历的时候就不会将该值添加到目标字符串中了,目标字符串存储结果。其他的都输出常规思路,还好不卡时间。

    #include<cstdlib>
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    using namespace std;
    int main()
    {
        string s1,s2;
        while(cin>>s1>>s2)
        {
            string put;
            int len1=s1.length();
            int len2=s2.length();
            int flag;
            for(int i=0;i<len1;i++)
            {
                if(s1[i]>='a'&&s1[i]<='z')
                {
                    s1[i]=s1[i]-32;
                }
            }
            for(int i=0;i<len2;i++)
            {
                if(s2[i]>='a'&&s2[i]<='z')
                {
                    s2[i]=s2[i]-32;
                }
            }
         //  cout<<s1<<endl;
         //   cout<<s2<<endl;
            for(int i=0;i<len1;i++)
            {
                flag=0;
                for(int j=0;j<s2.length();j++)
                {
                    if(s1[i]==s2[j])
                    {
                        flag=1;
                    }
                }
                if(flag==0)
                {
                    put.push_back(s1[i]);
                    s2.push_back(s1[i]);
                   // cout<<s2<<endl;
                    continue;
                }
            }
            cout<<put<<endl;
        }
    }
    


    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    DataGridView
    View Designer
    错题集
    MetalKit_1
    倍道而行:选择排序
    ARKit_3_任意门
    ARKit__2_尺子项目
    关于scrollview的无限滚动效果实现
    tableview折叠动效
    NSURLSession的简单使用
  • 原文地址:https://www.cnblogs.com/Tobyuyu/p/4965300.html
Copyright © 2020-2023  润新知