ASCII排序

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zheweizhe/article/details/73017605
代码部分
/*01.
02.*程序的版权和版本声明部分
03.*Copyright(c)2017,CSDN学院
04.*All rightsreserved.
05.*文件名称:
06.*作者:郑伟哲
07.*完成日期:2017年6月11日
08.*版本号:v1.0
09.*输入描述:输入数据有多组,每组占一行,有三个字符组成,之间无空格。
10.*问题描述:输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。

11. 输出描叙:对于每组输入数据,输出一行,字符中间用一个空格分开。
input   qwe
        asd
        zxc
output e q w
       a s d
       c x z
12.做了这题的心得
数组还是不是很熟悉好需要加强 
13.有哪些不明白  &str 不怎么懂,为甚末要这样定义 
14.运行状况:
15.*/
#include<stdio.h>
int main()
{
	char str[3],t;
	while(scanf("%s",&str)!=EOF)
	{
		int i;
		for(i=0;i<2;i++)
		{
			if(str[i]>str[i+1])
			{
				t=str[i];
				str[i]=str[i+1];
				str[i+1]=t;
			}
			if(str[0]>str[2])
			{
				t=str[0];
				str[0]=str[2];
				str[2]=t;
			}
		}
		printf("%c %c %c\n",str[0],str[1],str[2]);
	}
	return 0;
}


运行结果

其他解法

#include<stdio.h>
int main()
{
	char a,b,c,t;
	while(scanf("%c%c%c\n",&a,&b,&c)!=2)
{
	if(a>b);
	else
	{
	t=a;
	a=b;
	b=t;
	}
	if(a>c)
	{
	    if(b>c)
	  {
	  	printf("%c %c %c\n",c,b,a);
	  }
	  else
	  {
	  printf("%c %c %c\n",b,c,a);
	  }
	}
	else
	{
		printf("%c %c %c\n",b,a,c);
	}
}
	return 0;
 } 
 


这有个问题,

运行结果


猜你喜欢

转载自blog.csdn.net/zheweizhe/article/details/73017605