为什么你用GPT写文章总像模板?因为少了一套完整工作流
2026/7/6 2:44:58
#include <iostream> #include <string> using namespace std; int main() { cout << "功能说明:只删除字符串中间的*,开头和末尾的*全部保留" << endl; cout << "请输入带*的字符串:"; string s; cin >> s; string res; int len = s.size(); for (int i = 0; i < len; i++) { char ch = s[i]; // 判断条件:如果是中间位置的*,跳过不加入结果 if (ch == '*' && i != 0 && i != len - 1) { continue; } res += ch; } cout << "\n处理后的字符串:" << res << endl; return 0; }