过滤多余的空格-题解

描述

一个句子中也许有多个连续空格,过滤掉多余的空格,只留下一个空格。

输入描述

一行,一个字符串(长度不超过200),句子的头和尾都没有空格。

输出描述

过滤之后的句子。

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <bits/stdc++.h>
using namespace std;

int main(){
vector<string> v;
string tmp;
while(cin >> tmp){
v.push_back(tmp);
}
for(string s:v){
cout << s << " ";
}
return 0;
}


过滤多余的空格-题解
https://chenxi-tijie.pages.dev/2025/07/过滤多余的空格-题解/
作者
chenxi
发布于
2025年7月4日
许可协议