1029 Old keyboard (20 points)

Title: 1029 Old keyboard (20 points)

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

Ideas:

  • In fact, the idea is very simple, with the code c ++ STL containers in particularly simple.
  1. Define three variable name string function after using the find string () function to find out whether there is a character in s1 in s2, and if the character does not exist in ans, that the character has not looked for will in line with the added character ans go.
  2. Use to determine whether the string :: npos found, string :: npos is a constant, the value itself equal to -1, but because it is of type unsigned int, and therefore may be considered to be unsigned maximum value of type int (4294967295).

Code:

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #include <sstream>
 5 #include <cmath>
 6 #include <algorithm>
 7 #include <string>
 8 #include <stack>
 9 #include <queue>
10 #include <vector>
11 #include <map>
12 using namespace std;
13 
14 int main()
15 {
16     string s1, s2, ans;
17     cin >> s1 >> s2;
18     for(int i = 0; i < s1.length(); i++)
19     {
20         if(s2.find(s1[i]) == string::npos && ans.find(toupper(s1[i])) == string::npos)
21             ans += toupper(s1[i]);
22     }
23     cout << ans;
24     return 0;
25  } 

 

to sum up:

Guess you like

Origin www.cnblogs.com/Anber82/p/11271621.html