#藍橋杯練習#字符刪除

[藍橋杯][算法訓練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]);
    //}這樣寫也可以,但是比較麻煩
}
發佈了149 篇原創文章 · 獲贊 8 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章