zoukankan      html  css  js  c++  java
  • A1084. Broken Keyboard

    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

     1 #include<cstdio>
     2 #include<iostream>
     3 using namespace std;
     4 int trans(char c){
     5     if(c >= 'a' && c <= 'z')
     6         return c - 'a' + 10;
     7     else if(c >= 'A' && c <= 'Z')
     8         return c - 'A' + 10;
     9     else if(c >= '0' && c <= '9')
    10         return c - '0';
    11     else return 36;
    12 }
    13 int main(){
    14     char a[81], b[81];
    15     int hashTab[37] = {0,0};
    16     scanf("%s %s", a, b);
    17     for(int i = 0; b[i] != ''; i++){
    18         hashTab[trans(b[i])]= 1;
    19     }
    20     for(int i = 0; a[i] != ''; i++){
    21         if(hashTab[trans(a[i])] == 0){
    22             hashTab[trans(a[i])] = 1;
    23             if(a[i] <= 'z' && a[i] >= 'a')
    24                 printf("%c", a[i] - 'a' + 'A');
    25             else printf("%c", a[i]);
    26         }
    27     }
    28     cin >> a;
    29     return 0;
    30 }
    View Code

    总结:

    1、由于本题不区分大小写,所以将大小写字母映射为10-35, _映射为36, 0-9映射为0-9即可。如果区分大小写,则可以直接将ASCII的个数128映射为数组下标。

  • 相关阅读:
    silverlight 中缓存应用程序相应的库文件
    Silverlight 4 Unleashed 读书笔记:第二章
    使用虚拟打印机提交文档的文本
    ORACLE 中为什么要把列名都转换成大写字母?
    在 silverlight 自由绘图(WriteableBitmapEx)
    新的 WINDOWS 2003 系统上装了 TOMCAT 6 启动不了
    计算两个坐标所形成的角的角度
    在 Silverlight 绘制线帽(箭头)
    Linux下安装memecache缓存程序
    Linux下安装、配置、启动Apache
  • 原文地址:https://www.cnblogs.com/zhuqiwei-blog/p/8495338.html
Copyright © 2011-2022 走看看