PAT 甲级 散列 1084 Broken Keyboard (20 分)

灰太狼 2024-02-19 21:37 144阅读 0赞

1084 Broken Keyboard (20 分)

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:

  1. 7_This_is_a_test
  2. _hs_s_a_es

Sample Output:

  1. 7TI
  2. #include<iostream>
  3. #include<algorithm>
  4. #include<map>
  5. #include<cstring>
  6. #include<ctype.h>
  7. using namespace std;
  8. int main()
  9. {
  10. char a[81],b[81];
  11. string c;
  12. int i,j,len1,len2,k;
  13. map<char,int> d;
  14. cin>>a;
  15. cin>>b;
  16. len1=strlen(a);
  17. len2=strlen(b);
  18. for(i=0,j=0;i<len1&&j<len2;)
  19. {
  20. // cout<<a[i]<<" "<<b[j]<<endl;
  21. if(a[i]==b[j])
  22. {
  23. i++;
  24. j++;
  25. }
  26. else
  27. if(b[j]!=a[i])
  28. {
  29. a[i]=toupper(a[i]);
  30. if(d.count(a[i])==0)
  31. {
  32. d.insert(make_pair(a[i],1));
  33. c+=a[i];
  34. }
  35. i++;
  36. }
  37. }
  38. if(i<len1)
  39. for(k=i;k<len1;k++)
  40. {
  41. a[k]=toupper(a[k]);
  42. if(d.count(a[k])==0)
  43. c+=a[k];
  44. }
  45. if(j<len2)
  46. for(k=j;k<len2;k++)
  47. {
  48. a[k]=toupper(a[k]);
  49. if(d.count(a[k])==0)
  50. c+=b[k];
  51. }
  52. cout<<c<<endl;
  53. return 0;
  54. }

发表评论

表情:
评论列表 (有 0 条评论,144人围观)

还没有评论,来说两句吧...

相关阅读