c++代码
#include<iostream>
using namespace std;
int main()
{
string s1,s2;
getline(cin, s1);
int cnt = 0;
int flag = 1;
for(int i = 0; s1[i]; i ++ )
{
if(s1[i] != ' ') {
s2 += s1[i];
flag = 1;
}else{
if(flag) s2 += ' ';
flag = 0;
}
}
cout << s2 << endl;
return 0;
}