日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

字符串去除特定字符

發(fā)布時(shí)間:2024/4/11 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 字符串去除特定字符 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題目描述

輸入字符串s和字符c,要求去掉s中所有的c字符,并輸出結(jié)果。

輸入描述:

測(cè)試數(shù)據(jù)有多組,每組輸入字符串s和字符c。

輸出描述:

對(duì)于每組輸入,輸出去除c字符后的結(jié)果。

  • 示例1
    • 輸入
      heallo
      a
    • 輸出
      hello
#include <iostream> #include <fstream> #include <string> #include <ostream> #include <iterator> #include <vector> #include <algorithm> #include <map> #include <queue> #include <unordered_set> #include "cstring"#define N 1001 using namespace std;int getStringLength(const char array[]) {int length = 0;if (array == nullptr) {return length;}while (array[length] != '\0') {length++;}return length; }/*** 鍵盤輸入一行數(shù)據(jù)* @return*/ char *getLineMessage() {// 預(yù)先準(zhǔn)備的大小int preSize = 2;int len = preSize;int totalSize = preSize;char *line = static_cast<char *>(malloc(preSize * sizeof(char))), *str = line;int c;// 申請(qǐng)內(nèi)存失敗if (line == nullptr) {return nullptr;}for (;;) {c = fgetc(stdin);// 輸入是終止if (c == EOF) {break;}//判斷是否已經(jīng)用盡空間if (--len == 0) {len = totalSize;totalSize = totalSize * 2;char *newLine = static_cast<char *>(realloc(str, totalSize));if (newLine == nullptr) {free(str);return nullptr;}// 指針后移line = newLine + (line - str);str = newLine;}if ('\n' == (*line++ = c)) {break;}}*(--line) = '\0';return str; }int main() {char *message = getLineMessage();char target;cin >> target;int length = strlen(message);int j = 0;for (int i = 0; i < length; i++) {if (message[i] != target) {message[j++] = message[i];}}message[j] = '\0';cout << message << endl;return 0; // nwlrmqhcdarzowkkyhiddqscdxrjmowfrxsjyldefsarcynecdyggxxpklorellnmpapqfwkhopkmcoqhnwnkuewhsqmg // nwlrmqhcdarzowkkyhiddqscdxrjmowfrxsjyldefsarcynecdyggxxpklorellnmpapqfwkhopkmcoqhnwnkuewhsqmg}

總結(jié)

以上是生活随笔為你收集整理的字符串去除特定字符的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。