例如:
原字符串1234567890He is a man no12 3456
输出1234567890eH si a nam on12 3456
即以空格为分隔符,数字原样输出,分隔的子字符串则逆序输出。这里的逆序可以借助栈
#include <string.h>
#include <iostream>
#include <utility>
#include <vector>
#include<stack>
using namespace std;
/*****************************************************************************
Description : 转换字符串
Input Param : char *pInputStr 指向一个字符串的指针
long lInputLen 该字符串的长度
char *pOutputStr 指向一块输出的内存,和输入的字符串是大小是(lInputLen+1)
Output Param : 无
Return Value : 无
*****************************************************************************/
void vConvertMsg(char *pInputStr, long lInputLen, char *pOutputStr)
{
/* 在这里实现功能,将结果填入输入数组中 */
if(pInputStr == NULL || strlen(pInputStr) == 0 || lInputLen == 0 || pOutputStr == NULL)
{
return;
}
stack<char> s;
int i = 0;
int j = 0;
while(pInputStr[i] != '\0')
{
if(isalpha(pInputStr[i]))
{
if(s.empty())
{
j = i;
}
s.push(pInputStr[i]);
}
else
{
if(!s.empty())
{
while(!s.empty())
{
pOutputStr[j] = s.top();
s.pop();
j++;
}
}
pOutputStr[i] = pInputStr[i];
}
i++;
}
pOutputStr[i] = '\0';
return;
}