您的位置:首页 > 其它

hdu_1062 Text Reverse(水题)

2014-05-25 09:51 323 查看
题目链接:click here~~

题意是给出一个句子,把句子中的每个单词反转,空格原样输出。

#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n;
char a[1005];
char temp[1005];

scanf("%d",&n);
getchar();
while(n--)
{
memset(a,'\0',sizeof(a));
memset(temp,'\0',sizeof(temp));
gets(a);
a[strlen(a)] = ' ';
int start = 0;
for(int i = 0; i < strlen(a); i++)
{
if(a[i] != ' ' && a[i] != '\t')
temp[start ++] = a[i];
else
{
//if(start == 0) continue;
//else{
for(int j = start - 1; j >= 0; j--)
printf("%c",temp[j]);
//printf("%c",temp[0]);
if(i == strlen(a) - 1)
printf("\n");
else printf("%c",a[i]);
memset(temp,'\0',sizeof(temp));
start = 0;
//}
}
}
}
//printf("\n");
}


如果有更好更简洁代码,欢迎评论交流。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: