PTA (Basic Level) 1029. Old Keyboard

Broken a few keys on the keyboard old, so knocking a text when the corresponding character will not appear. Now a text input should be given, as well as the actual text is entered, you list those key definitely broken.

Input formats:

In the text input line 2 should be given in input, respectively, and the actual text input. Each piece of text is a string of no more than 80 characters, composed of letters AZ (including upper and lower case), numbers 0-9, and the underscore _(on behalf of spaces) components. Topic guarantee two strings are not empty.

Output formats:

Found in accordance with the order, the output key in broken line. Uppercase letters in which only output, output for each key only once bad. Topic ensure that at least one bad key.

Sample input:
7_This_is_a_test
_hs_s_a_es
Sample output:
7TI
Thinking
  • Traversal to find the string should enter the characters do not appear
  • Every time a character is found to see if there is no answer in the ( de-emphasis )
Code
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string right, wrong;
    cin >> right;
    cin >> wrong;

    string ans = "";
    for(int i=0;i<right.size();i++)
    {
        bool f = true;
        for(int j=0;j<wrong.size();j++)
            if(right[i] == wrong[j])
                f = false;
        if(f)    //说明没找到
        {
            char ch = toupper(right[i]);
            bool exist = false;
            for(int k=0;k<ans.size();k++)
                if(ch == ans[k])
                    exist = true;
            if(!exist)
                ans += ch;
        }
    }
    cout << ans;
    return 0;
}
Quote

https://pintia.cn/problem-sets/994805260223102976/problems/994805292322111488

Guess you like

Origin www.cnblogs.com/MartinLwx/p/11614144.html