高分求一段C++代码!字符串转换的!

来源:百度知道 编辑:UC知道 时间:2024/06/15 13:16:58
等待输入一句话,然后将其中间的某部分颠倒。比如有一句话: this is a boy要转换成this si a yob
怎么实现把一句话的第偶数个单词就要被倒过来
我不要理论 理论我也知道 我要实现....

/// 没有对第一个就是空格和里面有多个空格进行过滤,请自己修改
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <malloc.h>
#include <iostream.h>
#define STRINGLEN 1024
void main()
{
int i = 0;
char *pstrMsg = new char[STRINGLEN];
memset(pstrMsg , 0 , STRINGLEN);

// 接收输入
for (i = 0 ; i < STRINGLEN - 1 ; i ++)
{
char ch = getch();
if (ch == 13)
{
break;
}
pstrMsg[i] = ch;
printf("%c" , ch);
}
int strLen = strlen(pstrMsg);
char *pstrTmp = new char[strLen + 1];
memcpy(pstrTmp , pstrMsg , strLen + 1);
int iStart = 0;
int iEnd = 0;
bool isD = false;
for (i = 0 ; i <= strLen ; i ++)
{
if (pstrMsg[i] == ' ' || pstrMsg == '\0')
{
if (isD)
{
isD = false;
iEnd = i - 1; // 偶数行的结束位置
if (iEnd == iSta