PAT (Basic Level) Practice (中文)
announcement
PAT original site users can https://patest.cn/bind_old_pat_user bound to A title fight Account page. After binding, the site of the original PAT submission will be incorporated into the title fight A website user corresponding topic focus.
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:
A method to convert lower case letters.
Another method: uppercase and lowercase letters simultaneously labeled
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
int mp[109];
int main(void){
string s1,s2;
cin>>s1>>s2;
int cur =0;
for( int i=0;i<s1.length();i++){
if( s1[i] != s2[cur] ){
if( mp[s1[i]] ==0 ){
if( s1[i] >='a' && s1[i] <='z'){
printf("%c",s1[i]-32);
mp[s1[i]]++;
mp[s1[i]-32]++;
}
else {
printf("%c",s1[i]);
mp[s1[i]]++;
if( s1[i] >='A' &&s1[i] <= 'Z'){
mp[s1[i]+32]++;
}
}
}
}
else cur++;
if( cur ==s2.length()) {
cur =0;
s2[0] ='@';
}
}
printf("\n");
return 0;
}