#蓝桥杯练习#字符删除

那年仲夏 提交于 2020-01-22 05:20:01

[蓝桥杯][算法训练VIP]字符删除

在这里插入图片描述

#include<bits/stdc++.h>

using  namespace  std;

int  main()
{
    freopen("in.txt","r",stdin);
    char str[25], s[25], ch;
    gets(str);
    //scanf("%s", str);
    //getchar();这个不对,用gets
    scanf("%c", &ch);
    int i, j, len;
    len = strlen(str);
    j = 0;
    for(i = 0; i < len; i++)
    {
        if(str[i] != ch)
        {
            s[j++] = str[i];
        }
    }
    s[j] = '\0';
    printf("%s", s);
    //for(i = 0; i < j; i++)
    //{
    //    printf("%c", s[i]);
    //}这样写也可以,但是比较麻烦
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!