HZNUOJ1586—删字符 题解

    技术2022-07-11  76

    HZNUOJ1586—删字符 题解

    题目链接

    问题描述

    Description 给出字符和字符串,从字符串中删除指定字符并输出。例如从字符串"AscADef"中删除’A’后,字符串为"scDef"。

    Input 需要删除的字符ch。

    需要处理的字符串(长度不超过1000)。

    Output 处理后的字符串。

    Samples input A AscADef output scDef

    简单的字符串处理 遍历寻找目标字符逐个输出即可

    #include<stdio.h> #include<string.h> int main() { char n; char s[1000]; scanf("%c", &n); getchar(); scanf("%s", s); int len = strlen(s); for (int i = 0; i < len; i++) { if (s[i] != n)printf("%c", s[i]); } return 0; }
    Processed: 0.010, SQL: 9