解题思路:用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语言训练-求s=a+aa+aaa+aaaa+aa...a的值 (C语言代码)浏览:605 |
高精度加法 (C++代码)(大数加法)浏览:942 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:590 |
C语言程序设计教程(第三版)课后习题6.2 (C语言代码)浏览:721 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:612 |
数字游戏 (C++代码)浏览:1202 |
1054题解浏览:478 |
Tom数 (C语言代码)浏览:538 |
永远的丰碑 (C语言代码)浏览:535 |
C语言程序设计教程(第三版)课后习题10.5 (C语言代码)浏览:567 |