您的位置:首页 > 职场人生

面试题:输入一个英文句子,翻转句子中单词的顺序,但单词内字符的顺序不变。句子中单词以空格符隔开。

2016-09-26 10:23 441 查看
#include<iostream>
#include<math.h>
using namespace std;

char *Fun(char temp[])
{
int len = strlen(temp);
//cout<<len<<endl;
for(int i = 0, j = len - 1; i <= j; i++, j--)
{
char temp1 = temp[j];
temp[j] = temp[i];
temp[i] = temp1;
}
//
int j, k, p = 0;
for(int i = 0; i < len - 1; i++)
{
if(temp[i] == ' ')
{
for(k = p, j = i - 1; k <= j; k++, j--)
{
char temp1 = temp[k];
temp[k] = temp[j];
temp[j] = temp1;
}
p = i + 1;
}
}
return temp;
}

void main()
{
char str[100];
gets(str);
cout<<Fun(str)<<endl;
system("pause");
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐