金山笔试题-字符串排序 :" 写一个函数,实现对给定的字符串(字符串里面包括:英文字母,数字,符号)的处理"

   写一个函数,实现对给定的字符串(字符串里面包括:英文字母,数字,符号)的处理。经过处理后的字符串其内容按字母,数字,符号的顺序存放。函数声明如下:
void ParseString(char* pstr);

要求:

a.      不能改函数声明;

b.      不改变字母数字等在字符串中原有的出现顺序;

c.      直接使用pstr所值指缓冲区,不允许另开缓冲区。


本来不会做,问了同学才知道用冒泡法,比较规则按类型比较



// maopao.cpp : 定义控制台应用程序的入口点。
//


#include "stdafx.h"
#include 
#include 
#include 
using namespace std;


// 大于 1 等于0 小于 -1
int compare(char a,char b)
{
	if(isalpha(a))
	{
		if(isalpha(b))
		{
			return 0;
		}
		else
		{
			return 1;
		}
	}
	else if(isdigit(a))
	{
		if(isalpha(b))
		{
			return -1;
		}
		else if(isdigit(b))
		{
			return 0;
		}
		else 
		{
			return 1;
		}

	}
	else
	{
		if(isalpha(b) || isdigit(b))
		{
			return -1;
		}
		else 
		{
			return 0;
		}
	}

	

}

void ParseString(char* pstr)
{
	bool changed = false;
	int n = strlen(pstr);
	do 
	{	changed =false;
		for(int i=1;i


你可能感兴趣的:(【C++学习笔记】)