zoukankan      html  css  js  c++  java
  • 旧键盘打字

    链接:http://www.nowcoder.com/pat/6/problem/4059

    题目描述

    旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及坏掉的那些键,打出的结果文

    字会是怎样?

    输入描述:

    输入在2行中分别给出坏掉的那些键、以及应该输入的文字。其中对应英文字母的坏键以大写给出;每段文字是不超过105个字符的串。可用的

    字符包括字母[a-z, A-Z]、数字0-9、以及下划线“_”(代表空格)、“,”、“.”、“-”、“+”(代表上档键)。题目保证第2行输入的文字串非空。



    注意:如果上档键坏掉了,那么大写的英文字母无法被打出。



    输出描述:

    在一行中输出能够被打出的结果文字。如果没有一个字符能被打出,则输出空行。

    输入例子:

    7+IE.

    7_This_is_a_test.

    输出例子:

    _hs_s_a_tst

    思路:给可以存在的每个字符一个变量,用来保存该字符的键是好是坏。然后再对着检查就行了。但是代码不简洁。
      1 #include "iostream"
      2 #include <iomanip>
      3 #include <string.h>
      4 #include <string>
      5 #include <vector>
      6 #include <cmath>
      7 #include <cctype>
      8 #include <algorithm>
      9 using namespace std;
     10 
     11 const int MAXN = 100005;
     12 int num[MAXN];
     13 
     14 bool cmp(int a, int b)
     15 {
     16     return a<b;
     17 }
     18 
     19 int mark[41];
     20 
     21 int main()
     22 {
     23     string strErr, strSor, strDes;
     24     cin >>strErr >>strSor;
     25     for(int i=0; i<strErr.length(); ++i)
     26     {
     27         if(isdigit(strErr[i]))    mark[strErr[i]-'0'] = 1;
     28         else
     29         {
     30             if(isupper(strErr[i]))    mark[strErr[i]-'A'+10] = 1;
     31             else
     32             {
     33                 if(islower(strErr[i]))    mark[strErr[i]-32-'A'+10] = 1;
     34                 else
     35                 {
     36                     if(strErr[i] == '_')    mark[36] = 1;
     37                     else
     38                     {
     39                         if(strErr[i] == ',')    mark[37] = 1;
     40                         else
     41                         {
     42                             if(strErr[i] == '.')    mark[38] = 1;
     43                             else
     44                             {
     45                                 if(strErr[i] == '-')    mark[39] = 1;
     46                                 else    mark[40] = 1;
     47                             }
     48                         }
     49                     }
     50                 }
     51             }
     52         }
     53     }
     54     for(int i=0; i<strSor.length(); ++i)
     55     {
     56         if(isdigit(strSor[i]))
     57         {
     58             if(mark[strSor[i]-'0'] == 1)    continue;
     59         }
     60         else
     61         {
     62             if(isupper(strSor[i]))
     63             {
     64                 if(mark[strSor[i]-'A'+10]==1 ||
     65                    mark[40] == 1)    continue;
     66             }
     67             else
     68             {
     69                 if(islower(strSor[i]))
     70                 {
     71                     if(mark[strSor[i]-32-'A'+10] == 1)    continue;
     72                 }
     73                 else
     74                 {
     75                     if(strSor[i] == '_')
     76                     {
     77                         if(mark[36] == 1)    continue;
     78                     }
     79                     else
     80                     {
     81                         if(strSor[i] == ',')
     82                         {
     83                             if(mark[37] == 1)    continue;
     84                         }
     85                         else
     86                         {
     87                             if(strSor[i] == '.')
     88                             {
     89                                 if(mark[38] == 1)    continue;
     90                             }
     91                             else
     92                             {
     93                                 if(strSor[i] == '-')
     94                                 {
     95                                     if(mark[39] == 1)    continue;
     96                                 }
     97                                 else
     98                                 {
     99                                     if(mark[40] == 1)    continue;
    100                                 }
    101                             }
    102                         }
    103                     }
    104                 }
    105             }
    106         }
    107         strDes += strSor[i];
    108     }
    109     cout <<strDes <<endl;
    110     return 0;
    111 }
  • 相关阅读:
    python基本数据类型及其使用方法
    爬虫基础
    HTML标签marquee实现滚动效果
    Python学习之路_day_32(基于tcp协议的套接字/粘包问题)
    Python学习之路_day_31(tcp协议/socket)
    Python学习之路_day_30(单例模式,网络编程)
    Python学习之路_day_29(异常处理,元类)
    Python学习之路_day_25(面向对象之封装/多态/组合)
    Python学习之路_day_24(面向对象之继承)
    Python学习之路_day_23(面向对象)
  • 原文地址:https://www.cnblogs.com/mtc-dyc/p/4626508.html
Copyright © 2011-2022 走看看