解题思路:用STL的erase来删除空格
注意事项:
参考代码:
#include <deque>
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <iterator>
#include <numeric>
#include <string>
#include <string.h>
using namespace std;
int main()
{
int k=0;
deque<string> q;
string str;
while(getline(cin,str))
{
for(int i=0;i<str.size();i++)
{
if(str[i]==' ')
{
str.erase(str.begin()+i,str.begin()+i+1);
}
}
q.push_back(str);
}
copy(q.begin(),q.end(),ostream_iterator<string>(cout,"\n"));
return 0;
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题6.4 (C语言代码)浏览:602 |
最小公倍数 (C语言代码)浏览:871 |
C语言训练-求函数值 (C语言代码)浏览:585 |
2004年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:511 |
2006年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:489 |
用筛法求之N内的素数。 (C语言代码)浏览:870 |
C语言程序设计教程(第三版)课后习题8.4 (C语言代码)浏览:611 |
最小公倍数 (C语言代码)浏览:1041 |
1908题解浏览:656 |
文科生的悲哀 (C语言代码)浏览:1424 |