2014-4-25 运行号:837344 ASCII码排序

 
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

void cmp(char s[]){
	int i=0;
	char tmp;
	if(s[0]>s[1]){
		tmp = s[0];
		s[0] = s[1];
		s[1] =tmp;
	}
	if(s[0]>s[2]){
		tmp = s[0];
		s[0] = s[2];
		s[2] =tmp;
	}
	if(s[1]>s[2]){
		tmp = s[1];
		s[1] = s[2];
		s[2] =tmp;
	}
}
int main(){
	int n;
	char s[4];
	scanf("%d",&n);
	for(int i = 0;i<n;++i){
		scanf("%s",s);
		cmp(s);
		for(int j=0;j<3;++j){
			printf("%c ",s[j]);
		}
		printf("\n");
	}
	return 0;
}
        

 ASCLL排序 只有一点要注意,就是c语言定义数组的时候要要比所要求的大小多一点,大小一样的话会发生溢出

posted @ 2014-04-26 11:16  sunalive  Views(163)  Comments(0)    收藏  举报