Links: http://www.nowcoder.com/pat/6/problem/4059
Title Description
The old keyboard has broken a few keys, so when you hit a piece of text, the corresponding characters will not appear. Now give the text that should be entered, and the broken keys, the resulting text
What's the word going to be?
Input Description:
Enter the keys that were broken in 2 rows, and the text that should be entered. The bad key corresponding to the English letter is given in uppercase, and each paragraph is a string of no more than 105 characters. Available for
The characters include the letters [a-Z, A-z], the number 0-9, and the Underscore "_" (for spaces), ",", ".", "-", "+" (on behalf of the upper file key). The title guarantees that the text string entered in line 2nd is not empty.
Note: If the upper file key is broken, the uppercase English letter cannot be typed.
Output Description:
Outputs the result text that can be typed in a row. If no word rp is typed, a blank line is output.
Input Example:
7+ie.
7_this_is_a_test.
Output Example:
_hs_s_a_tst
Idea: Given a variable that can exist for each character, the key used to hold the character is good or bad. And then check it out. But the code is not concise.
1#include"iostream"2#include <iomanip>3#include <string.h>4#include <string>5#include <vector>6#include <cmath>7#include <cctype>8#include <algorithm>9 using namespacestd;Ten One Const intMAXN =100005; A intNUM[MAXN]; - - BOOLcmpintAintb) the { - returna<b; - } - + intmark[ A]; - + intMain () A { at stringStrerr, Strsor, strdes; -CIN >>strerr >>Strsor; - for(intI=0; I<strerr.length (); ++i) - { - if(IsDigit (Strerr[i])) mark[strerr[i]-'0'] =1; - Else in { - if(Isupper (Strerr[i])) mark[strerr[i]-'A'+Ten] =1; to Else + { - if(Islower (Strerr[i])) mark[strerr[i]- +-'A'+Ten] =1; the Else * { $ if(Strerr[i] = ='_') mark[ $] =1;Panax Notoginseng Else - { the if(Strerr[i] = =',') mark[Panax Notoginseng] =1; + Else A { the if(Strerr[i] = ='.') mark[ -] =1; + Else - { $ if(Strerr[i] = ='-') mark[ the] =1; $ Elsemark[ +] =1; - } - } the } - }Wuyi } the } - } Wu for(intI=0; I<strsor.length (); ++i) - { About if(IsDigit (Strsor[i])) $ { - if(mark[strsor[i]-'0'] ==1)Continue; - } - Else A { + if(Isupper (Strsor[i])) the { - if(mark[strsor[i]-'A'+Ten]==1|| $mark[ +] ==1)Continue; the } the Else the { the if(Islower (Strsor[i])) - { in if(mark[strsor[i]- +-'A'+Ten] ==1)Continue; the } the Else About { the if(Strsor[i] = ='_') the { the if(mark[ $] ==1)Continue; + } - Else the {Bayi if(Strsor[i] = =',') the { the if(mark[Panax Notoginseng] ==1)Continue; - } - Else the { the if(Strsor[i] = ='.') the { the if(mark[ -] ==1)Continue; - } the Else the { the if(Strsor[i] = ='-')94 { the if(mark[ the] ==1)Continue; the } the Else98 { About if(mark[ +] ==1)Continue; - }101 }102 }103 }104 } the }106 }107Strdes + =Strsor[i];108 }109cout <<strdes <<Endl; the return 0;111}
Old keyboard Typing