法一:利用cin不会读入空格
include[HTML_REMOVED]
include[HTML_REMOVED]
using namespace std;
int main()
{
string a;
while(cin>>a)
cout<<a<<” “;
return 0;
}
法二:将连续空格删掉
include[HTML_REMOVED]
using namespace std;
int main()
{
string s,r;
getline(cin,s);
int i;
for(i=0;i<s.size();i)
{
if(s[i]!=’ ‘)
r+=s[i];
else
{
r+=” “;
int j;
j=i;
while(j<s.size()&&s[j]==’ ‘)
j;
i=j-1;
}
}
cout<<r<<endl;
return 0;
}