[求助]ACM题,老PE,怎么也找不出问题!!!!!!!!!

hua_zhixing_ 2009-10-07 11:22:40
#include<iostream>
#include<string>
using namespace std;
int main(){
int m;
unsigned int n;
cin>>m;
cin.ignore();
for(int j=0; j<m; j++){
string s,t,l;
getline(cin, s);
n=s.size();
for(int i=0; i<n; i++){
if(i==n-1){
t=s[i]+t;
l+=t;
}
else if(s[i]!=' ') t=s[i]+t;
else{
t+=s[i];
l+=t;
t.clear();
}
}
cout<<l<<endl;
//if(j!=m-1) cout<<endl;//最后一行不换行也不行.
}
return 0;
}

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1062
...全文
209 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
baihacker 2009-10-08
  • 打赏
  • 举报
回复

//可能是空格个数的问题,我是原地翻转并AC的
#include<iostream>
#include<string>
using namespace std;
int main(){
int m;
unsigned int n;
cin>>m;
cin.ignore();
for(int j=0; j<m; j++){
string s,t,l;
getline(cin, s);
n=s.length();
for (int i = 0, j = 0;;)
{
while (i < n && s[i] == ' ') ++i;
if (i == n) break;
j = i;
while (j < n && s[j] != ' ') ++j;
for (int x = i, y = j - 1; x < y; swap(s[x++], s[y--]));
i = j;
}
cout<<s<<endl;
}
return 0;
}
ACgirl 2009-10-07
  • 打赏
  • 举报
回复
1楼所说的楼主已经正确处理了
ACgirl 2009-10-07
  • 打赏
  • 举报
回复
行末和和始的空格呢
booksoon 2009-10-07
  • 打赏
  • 举报
回复
Remember to use getchar() to read '\n' after the interger T, then you may use gets() to read a line and process it.
hua_zhixing_ 2009-10-07
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 chinayuppie 的回复:]
Remember to use getchar() to read '\n' after the interger T, then you may use gets() to read a line and process it.
[/Quote]
我试了下,还是不行啊,老兄!!!!

33,028

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧