【题目描述】
过滤多余的空格。一个句子中也许有多个连续空格,过滤掉多余的空格,只留下一个空格。
【输入】
一行,一个字符串(长度不超过200200),句子的头和尾都没有空格。
【输出】
过滤之后的句子。
【输入样例】
Hello world.This is c language.
【输出样例】
Hello world.This is c language.
#include <bits/stdc++.h>
using namespace std;
string s;
int main(){
int l,i;
while(cin>>s){//一直输入字符串,用cin输入是不会有空格的。
l=s.size();
if(s[l-1]=='.'){//判断是不是句末,是则不输出空格,否则输出空格。
cout<<s;
}
else{
cout<<s<<" ";
}
}
return 0;
}