#include <iostream>
#include <ctype.h>
using namespace std;
/*
a. 不能改函数声明;
b. 不改变字母数字等在字符串中原有的出现顺序;
c. 直接使用pstr所值指缓冲区,不允许另开缓冲区。
例如:给定的字符串为:A,2.d?3!e4r87we79...
输出结果为:Aderwe2348779,.?!...
*/
//冒泡排序
void ParseString(char* pstr)
{
if(pstr == NULL)
return;
int len = strlen(pstr);
// for(int i=len-1; i>0; i--)
// {
// for(int j=0; j<i; j++)
// {
//
// if( ( !isalpha(pstr[j]) && isalpha(pstr[j+1]) ) ||
// ( ispunct(pstr[j]) && !ispunct(pstr[j+1]) )
// )
// {
// char t = pstr[j];
// pstr[j] = pstr[j+1];
// pstr[j+1] = t;
// }
// }
// }
for(int i=0; i<len-1; i++)
{
for(int j=len-2; j>i; j--)
{
if( ( !isalpha(pstr[j]) && isalpha(pstr[j+1]) ) ||
( ispunct(pstr[j]) && !ispunct(pstr[j+1]) )
)
{
char t = pstr[j];
pstr[j] = pstr[j+1];
pstr[j+1] = t;
}
}
}
cout<<pstr<<endl;
}
void main()
{
char szText[] = "A,2.d?3!e4r87we79...";
ParseString(szText);
}
#include <ctype.h>
using namespace std;
/*
a. 不能改函数声明;
b. 不改变字母数字等在字符串中原有的出现顺序;
c. 直接使用pstr所值指缓冲区,不允许另开缓冲区。
例如:给定的字符串为:A,2.d?3!e4r87we79...
输出结果为:Aderwe2348779,.?!...
*/
//冒泡排序
void ParseString(char* pstr)
{
if(pstr == NULL)
return;
int len = strlen(pstr);
// for(int i=len-1; i>0; i--)
// {
// for(int j=0; j<i; j++)
// {
//
// if( ( !isalpha(pstr[j]) && isalpha(pstr[j+1]) ) ||
// ( ispunct(pstr[j]) && !ispunct(pstr[j+1]) )
// )
// {
// char t = pstr[j];
// pstr[j] = pstr[j+1];
// pstr[j+1] = t;
// }
// }
// }
for(int i=0; i<len-1; i++)
{
for(int j=len-2; j>i; j--)
{
if( ( !isalpha(pstr[j]) && isalpha(pstr[j+1]) ) ||
( ispunct(pstr[j]) && !ispunct(pstr[j+1]) )
)
{
char t = pstr[j];
pstr[j] = pstr[j+1];
pstr[j+1] = t;
}
}
}
cout<<pstr<<endl;
}
void main()
{
char szText[] = "A,2.d?3!e4r87we79...";
ParseString(szText);
}