解题思路:用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二级辅导-进制转换 (C语言代码)浏览:630 |
C语言训练-数字母 (C语言代码)浏览:592 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:612 |
完数 (C语言代码)浏览:714 |
有关字符,字符串的输入输出函数说明浏览:482 |
1048题解(读入回车问题)浏览:577 |
1035 题解浏览:803 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:534 |
1074题 初学者,求帮忙看下,不知道哪错了浏览:292 |
C语言程序设计教程(第三版)课后习题6.4 (C语言代码)浏览:465 |