1084. Broken Keyboard (20)

来源:互联网 发布:照片打印软件 编辑:程序博客网 时间:2024/04/28 18:48

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_es
Sample Output:
7TI
在typeOut长度范围内
    original和打出的typeOut一样
                                                 两者都加,
                                                 否则typeOut缺失看看这个缺失的在不再brokenkeys里面,不在加;
在typeOut长度范围外  看看剩下的original是否有不在brokenkeys里面的,不在加

评测结果

时间结果得分题目语言用时(ms)内存(kB)用户8月01日 14:07答案正确201084C++ (g++ 4.7.2)1436datrilla

测试点

测试点结果用时(ms)内存(kB)得分/满分0答案正确138412/121答案正确14363/32答案正确13041/13答案正确13041/14答案正确13083/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;} 
0 0
原创粉丝点击