zoukankan      html  css  js  c++  java
  • 1033 旧键盘打字 (20 分)C语言

    题目描述

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

    输入描述:

    输入在2行中分别给出坏掉的那些键、以及应该输入的文字。其中对应英文字母的坏键以大写给出;每段文字是不超过10^5个字符的串。可用的字符包括字母[a-z, A-Z]、数字0-9、以及下划线“_”(代表空格)、“,”、“.”、“-”、“+”(代表上档键)。题目保证第2行输入的文字串非空。
    注意:如果上档键坏掉了,那么大写的英文字母无法被打出。

    输出描述:

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

    输入例子:

    7+IE.
    7_This_is_a_test.
    

    输出例子:

    _hs_s_a_tst
    
    #include <stdio.h>
    int main() {
        int shuru = 0;
        char shu[128];
        char numb[100001];
        int same[128];
        gets(shu);
        gets(numb);
        int brok = strlen(shu);
        int chan = strlen(numb);
        int i,j;
        for (i = 0; i < brok; i++) {
            same[shu[i]] = 1;
            if (shu[i] >= 'A' && shu[i] <= 'Z') {
                same[shu[i] + 32] = 1;
            } else if (shu[i] >= 'a' && shu[i] <= 'z') {
                same[shu[i] - 32] = 1;
            }
        }
        for (j = 0; j < chan; j++) {
            if (same[numb[j]]) {
                continue;
            }
            if (numb[j] >= 'A' && numb[j] <= 'Z' && same['+']) {
                continue;
            }
            putchar(numb[j]);
            shuru++;
        }
        if (shuru == 0) {
            printf("
    ");
        }
    }
    

    网上的

    #include <stdio.h>
    #include <ctype.h>
    int main() {
        char A[123] = {
            0
        }, ch;
        while ((ch = getchar()) != '
    ') {
            A[ch]++;
        }
        while ((ch = getchar()) != '
    ') {
            if ((isupper(ch) && A[43]) || A[toupper(ch)]) {
                continue;
            }
            else {
                putchar(ch);
            }
        }
        return 0;
    }
    
    欢迎查阅
  • 相关阅读:
    第六次作业
    第五次作业1
    java第三次作业
    JAVA 第二次作业
    JAVA第一次作业
    第 十一 次作业
    第十次作业
    第九次作业
    第八次作业
    第七次作业
  • 原文地址:https://www.cnblogs.com/gh110/p/12158221.html
Copyright © 2011-2022 走看看