C++ 代码
#include<iostream>
using namespace std;
int main()
{
string str;
while(cin >> str)
{
cout << str <<' ';
}
return 0;
}//哈哈,取巧利用cin不读入空格的特点;
//其他方法
// #include <iostream>
// using namespace std;
// int main()
// {
// string a ;
// getline(cin,a);
// for(int i = 0 ; i < a.size() ; i ++ )
// {
// if(a[i] == ' ') //检测到空格
// {
// cout << ' ';//输出一个
// while(a[i+1] == ' ') //检测下一个是不是空格,是的话就跳过(i++)
// {
// i++;
// }
// }
// else cout << a[i];
// }
// }
//作者:冰语晨星