描述给定一个短字符串不含空格再给定若干字符串在这些字符串中删除所含有的短字符串。输入描述输入只有1组数据。输入一个短字符串不含空格再输入若干字符串直到文件结束为止。输出描述删除输入的短字符串不区分大小写并去掉空格输出希望能用c++编写代码不要讲解。输入:in#include int mainprintf Hi ;输出:#cludetmaprtfHi;
#include <iostream>
#include <string>
using namespace std;
int main() {
string shortStr;
getline(cin, shortStr); // 输入短字符串
string line;
while (getline(cin, line)) { // 输入多个字符串直到文件结束
// 删除短字符串并去掉空格
size_t pos = 0;
while ((pos = line.find(shortStr, pos)) != string::npos) {
line.erase(pos, shortStr.length());
}
line.erase(remove(line.begin(), line.end(), ' '), line.end());
cout << line << endl;
}
return 0;
}
原文地址: https://www.cveoy.top/t/topic/jae6 著作权归作者所有。请勿转载和采集!