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_esSample Output:7TI在typeOut长度范围内original和打出的typeOut一样两者都加,否则typeOut缺失看看这个缺失的在不再brokenkeys里面,不在加;在typeOut长度范围外 看看剩下的original是否有不在brokenkeys里面的,不在加
评测结果
时间 | 结果 | 得分 | 题目 | 语言 | 用时(ms) | 内存(kB) | 用户 |
---|---|---|---|---|---|---|---|
8月01日 14:07 | 答案正确 | 20 | 1084 | C++ (g++ 4.7.2) | 1 | 436 | datrilla |
测试点
测试点 | 结果 | 用时(ms) | 内存(kB) | 得分/满分 |
---|---|---|---|---|
0 | 答案正确 | 1 | 384 | 12/12 |
1 | 答案正确 | 1 | 436 | 3/3 |
2 | 答案正确 | 1 | 304 | 1/1 |
3 | 答案正确 | 1 | 304 | 1/1 |
4 | 答案正确 | 1 | 308 | 3/3 |
#include<iostream> #include<string> using namespace std; bool TheSame(char A, char B) { if (A == B || A >= 'a'&&A <= 'z'&&A - 'a' + 'A' == B) return true; return false; } char AddTheBag(char c) { if (c >= 'a'&&c <= 'z')return c - 'a' + 'A'; return c; } bool NoInbrokeys(string brokenkeys, char ctemp,int lenb) { int index; for (index = 0; index < lenb; index++) { if (brokenkeys[index] == ctemp || ctemp >= 'a'&&ctemp <= 'z'&&ctemp - 'a' + 'A' == brokenkeys[index]) return false; } return true; } int main() { string original, brokenkeys,typeOut; int oindex, tindex, leno,lent,lenb; cin >> original >> typeOut; leno = original.size(); lent = typeOut.size(); lenb = brokenkeys.size(); for (oindex = 0,tindex=0; oindex < leno; oindex++) { if (tindex < lent) { if (TheSame(original[oindex], typeOut[tindex])) { tindex++; } else if (NoInbrokeys(brokenkeys, original[oindex], lenb)) { brokenkeys += AddTheBag(original[oindex]); lenb++; } } else if (NoInbrokeys(brokenkeys, original[oindex], lenb)) { brokenkeys += AddTheBag(original[oindex]); lenb++; } } cout << brokenkeys << endl; system("pause"); return 0; }