zoukankan      html  css  js  c++  java
  • PAT (Basic Level) Practise:1029. 旧键盘

    【题目链接】

    旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及实际被输入的文字,请你列出肯定坏掉的那些键。

    输入格式:

    输入在2行中分别给出应该输入的文字、以及实际被输入的文字。每段文字是不超过80个字符的串,由字母A-Z(包括大、小写)、数字0-9、以及下划线“_”(代表空格)组成。题目保证2个字符串均非空。

    输出格式:

    按照发现顺序,在一行中输出坏掉的键。其中英文字母只输出大写,每个坏键只输出一次。题目保证至少有1个坏键。

    输入样例:

    7_This_is_a_test
    _hs_s_a_es
    

    输出样例:

    7TI

    【提交代码】

     1 #include <stdio.h>
     2 #include <string.h>
     3 
     4 int main(void)
     5 {
     6     int i;
     7     int table[10+26+1];
     8 
     9     char pStr1[100];
    10     char pStr2[100];
    11     char ch;
    12     int len1, len2;
    13     
    14     scanf("%s", pStr1);
    15     scanf("%s", pStr2);
    16 
    17     len1 = strlen(pStr1);
    18     len2 = strlen(pStr2);
    19 
    20     memset(table, 0x00, sizeof(table));
    21     // 记录“实际被输入的文字”的键,即没有坏的键
    22     for(i = 1; i <= len2; i++)
    23     {
    24         ch = pStr2[i-1];
    25         if(ch >= '0' && ch <= '9' && table[ch-'0'] == 0)
    26         {
    27             table[ch-'0'] = 1; 
    28         }
    29         else if(ch >= 'a' && ch <= 'z' && table[ch-'a'+10] == 0)
    30         {
    31             table[ch-'a'+10] = 1;
    32         }
    33         else if(ch >= 'A' && ch <= 'Z' && table[ch-'A'+10] == 0)
    34         {
    35             table[ch-'A'+10] = 1;
    36         }
    37         else if(ch == '_' && table[10+26] == 0)
    38         {
    39             table[10+26] = 1;
    40         }
    41     }
    42     // 从“应该输入的文字”中检测是否为“实际被输入的文字”
    43     // 如果不是“实际被输入的文字”则说明该键是坏掉的
    44     for(i = 1; i <= len1; i++)
    45     {
    46         ch = pStr1[i-1];
    47         if(ch >= '0' && ch <= '9')
    48         {
    49             if(table[ch-'0'] == 0)
    50             {
    51                 printf("%c", ch);
    52                 table[ch-'0'] = 1;
    53             }
    54         }
    55         else if(ch >= 'a' && ch <= 'z')
    56         {
    57             if(table[ch-'a'+10] == 0)
    58             {
    59                 printf("%c", ch-'a'+'A');
    60                 table[ch-'a'+10] = 1;
    61             }
    62         }
    63         else if(ch >= 'A' && ch <= 'Z')
    64         {
    65             if(table[ch-'A'+10] == 0)
    66             {
    67                 printf("%c", ch);
    68                 table[ch-'A'+10] = 1;
    69             }
    70         }
    71         else if(ch == '_')
    72         {
    73             if(table[10+26] == 0)
    74             {
    75                 printf("%c", ch);
    76                 table[10+26] = 1;
    77             }
    78         }
    79     }
    80 
    81     return 0;
    82 }
  • 相关阅读:
    数据结构----------------优先队列
    IDEA建立---- java web项目
    mysql 基础篇5(mysql语法---数据)
    数据库 基础篇4(mysql语法---表)
    数据库 基础篇3(mysql语法)
    数据库 基础篇2(mysql)
    vi保存搜索结果
    自定义修改connect rule
    xargs 的应用
    nfs,nis nobody的问题
  • 原文地址:https://www.cnblogs.com/utank/p/4277267.html
Copyright © 2011-2022 走看看