user-0 提问: 关于三个数特殊的排序问题

回复:
user: user-0
content: 引用 1 楼 user-4 的回复:用for循环啊，就像求n个数最大值一样，在里面加一个相等时的分支，相等就随机选 是这个意思啊。但是就是不太好写啊。。

user: user-0
content: 引用 3 楼 braycep 的回复:printf("%d",(n0>n1? n0:n1)>n2?(n0>n1? n0:n1):n2); 这个没有选择出方向吧？而且好像在有相同值的时候不适用吧？

user: user-0
content: 引用 2 楼 jiangzhiyuan123 的回复:int n[3]={1,2,3}; 	int max; 	max=n[0];        	int count=0;     //初始方向0； 	for(int i=0;i<2;i++) 	{ 		if(n[i]<=n[i+1]) 			max=n[i+1]; 		count=i+1; 	} 	printf("%d\n%d\n",max,count); 这个貌似不太行哦。比如n2=n3>n1，这时候我想要的是2和3两个方向中的任意一个，而不是固定的某一个。你这个代码好像只能选择一个，而且是最大的方向。我说的对吗？

user: user-0
content: 引用 7 楼 zhao4zhong1 的回复:这个世界上最大的差别和最远的距离都存在于“说”和“做”之间。 #include <stdio.h> #include <stdlib.h> #include <time.h> int n[3],m[3]; int i,j,k,t; int main() {     srand(time(NULL));     for (k=0;k<100;k++) {         for (i=0;i<3;i++) {             n[i]=rand()%4;             m[i]=i;         }         printf("%02d:%d %d %d ",k,n[0],n[1],n[2]);//第0..99次的三个数         for (i=0;i<2;i++) {             for (j=i+1;j<3;j++) {                 if (n[i]<n[j]) {                     t=n[i];n[i]=n[j];n[j]=t;                     t=m[i];m[i]=m[j];m[j]=t;                 }             }         }         if (n[0]==n[1] && n[1]==n[2]) {             i=rand()%3;//最大的三个都相等，随机选其中一个         } else if (n[0]==n[1]) {             i=rand()%2;//最大的两个都相等，随机选其中一个         } else i=0;         printf(" [%d] %d\n",m[i],n[i]);//选第[]个，值     }     return 0; } //00:1 1 3  [2] 3 //01:2 1 2  [0] 2 //02:1 2 2  [2] 2 //03:1 1 2  [2] 2 //04:3 3 2  [0] 3 //05:3 1 3  [2] 3 //06:2 0 2  [0] 2 //07:2 3 2  [1] 3 //08:0 2 1  [1] 2 //09:1 0 0  [0] 1 //10:1 1 3  [2] 3 //11:2 3 0  [1] 3 //12:3 2 2  [0] 3 //13:2 3 0  [1] 3 //14:0 1 3  [2] 3 //15:1 1 0  [0] 1 //16:1 0 3  [2] 3 //17:2 1 2  [0] 2 //18:3 3 0  [0] 3 //19:1 1 3  [2] 3 //20:2 3 0  [1] 3 //21:3 3 0  [0] 3 //22:0 3 1  [1] 3 //23:0 0 3  [2] 3 //24:0 0 0  [2] 0 //25:0 2 0  [1] 2 //26:2 3 1  [1] 3 //27:2 1 2  [2] 2 //28:2 2 0  [1] 2 //29:2 3 1  [1] 3 //30:2 2 0  [0] 2 //31:1 1 1  [2] 1 //32:2 2 0  [0] 2 //33:2 0 1  [0] 2 //34:3 0 2  [0] 3 //35:3 0 0  [0] 3 //36:1 2 1  [1] 2 //37:2 3 1  [1] 3 //38:0 0 0  [0] 0 //39:2 1 3  [2] 3 //40:3 3 0  [1] 3 //41:3 1 0  [0] 3 //42:3 1 1  [0] 3 //43:1 3 1  [1] 3 //44:3 3 0  [1] 3 //45:0 1 1  [1] 1 //46:0 1 3  [2] 3 //47:3 1 1  [0] 3 //48:2 0 0  [0] 2 //49:1 1 3  [2] 3 //50:2 0 3  [2] 3 //51:3 3 1  [1] 3 //52:2 2 3  [2] 3 //53:2 1 2  [0] 2 //54:3 1 3  [0] 3 //55:3 0 0  [0] 3 //56:2 1 0  [0] 2 //57:3 3 3  [0] 3 //58:1 3 3  [1] 3 //59:0 3 1  [1] 3 //60:1 2 1  [1] 2 //61:2 2 0  [0] 2 //62:0 1 3  [2] 3 //63:3 2 2  [0] 3 //64:1 0 3  [2] 3 //65:1 0 2  [2] 2 //66:2 1 2  [2] 2 //67:1 3 1  [1] 3 //68:1 2 3  [2] 3 //69:1 0 1  [2] 1 //70:2 0 3  [2] 3 //71:2 3 1  [1] 3 //72:3 2 3  [2] 3 //73:3 1 3  [2] 3 //74:1 0 0  [0] 1 //75:2 2 1  [1] 2 //76:2 2 3  [2] 3 //77:2 1 2  [0] 2 //78:2 3 3  [1] 3 //79:1 2 0  [1] 2 //80:1 0 3  [2] 3 //81:1 0 0  [0] 1 //82:0 0 1  [2] 1 //83:1 0 0  [0] 1 //84:2 1 0  [0] 2 //85:1 1 2  [2] 2 //86:0 0 0  [0] 0 //87:1 3 2  [1] 3 //88:1 0 2  [2] 2 //89:0 1 3  [2] 3 //90:3 0 2  [0] 3 //91:2 3 2  [1] 3 //92:1 1 2  [2] 2 //93:3 1 3  [0] 3 //94:2 2 2  [1] 2 //95:1 1 2  [2] 2 //96:1 1 1  [2] 1 //97:0 2 0  [1] 2 //98:3 3 1  [1] 3 //99:3 1 2  [0] 3 //  谢谢老师的委婉批评，程序简洁有效！

user: user-1
content: printf("%d",(n0>n1? n0:n1)>n2?(n0>n1? n0:n1):n2);

user: user-2
content: 这个世界上最大的差别和最远的距离都存在于“说”和“做”之间。 #include <stdio.h> #include <stdlib.h> #include <time.h> int n[3],m[3]; int i,j,k,t; int main() {     srand(time(NULL));     for (k=0;k<100;k++) {         for (i=0;i<3;i++) {             n[i]=rand()%4;             m[i]=i;         }         printf("%02d:%d %d %d ",k,n[0],n[1],n[2]);//第0..99次的三个数         for (i=0;i<2;i++) {             for (j=i+1;j<3;j++) {                 if (n[i]<n[j]) {                     t=n[i];n[i]=n[j];n[j]=t;                     t=m[i];m[i]=m[j];m[j]=t;                 }             }         }         if (n[0]==n[1] && n[1]==n[2]) {             i=rand()%3;//最大的三个都相等，随机选其中一个         } else if (n[0]==n[1]) {             i=rand()%2;//最大的两个都相等，随机选其中一个         } else i=0;         printf(" [%d] %d\n",m[i],n[i]);//选第[]个，值     }     return 0; } //00:1 1 3  [2] 3 //01:2 1 2  [0] 2 //02:1 2 2  [2] 2 //03:1 1 2  [2] 2 //04:3 3 2  [0] 3 //05:3 1 3  [2] 3 //06:2 0 2  [0] 2 //07:2 3 2  [1] 3 //08:0 2 1  [1] 2 //09:1 0 0  [0] 1 //10:1 1 3  [2] 3 //11:2 3 0  [1] 3 //12:3 2 2  [0] 3 //13:2 3 0  [1] 3 //14:0 1 3  [2] 3 //15:1 1 0  [0] 1 //16:1 0 3  [2] 3 //17:2 1 2  [0] 2 //18:3 3 0  [0] 3 //19:1 1 3  [2] 3 //20:2 3 0  [1] 3 //21:3 3 0  [0] 3 //22:0 3 1  [1] 3 //23:0 0 3  [2] 3 //24:0 0 0  [2] 0 //25:0 2 0  [1] 2 //26:2 3 1  [1] 3 //27:2 1 2  [2] 2 //28:2 2 0  [1] 2 //29:2 3 1  [1] 3 //30:2 2 0  [0] 2 //31:1 1 1  [2] 1 //32:2 2 0  [0] 2 //33:2 0 1  [0] 2 //34:3 0 2  [0] 3 //35:3 0 0  [0] 3 //36:1 2 1  [1] 2 //37:2 3 1  [1] 3 //38:0 0 0  [0] 0 //39:2 1 3  [2] 3 //40:3 3 0  [1] 3 //41:3 1 0  [0] 3 //42:3 1 1  [0] 3 //43:1 3 1  [1] 3 //44:3 3 0  [1] 3 //45:0 1 1  [1] 1 //46:0 1 3  [2] 3 //47:3 1 1  [0] 3 //48:2 0 0  [0] 2 //49:1 1 3  [2] 3 //50:2 0 3  [2] 3 //51:3 3 1  [1] 3 //52:2 2 3  [2] 3 //53:2 1 2  [0] 2 //54:3 1 3  [0] 3 //55:3 0 0  [0] 3 //56:2 1 0  [0] 2 //57:3 3 3  [0] 3 //58:1 3 3  [1] 3 //59:0 3 1  [1] 3 //60:1 2 1  [1] 2 //61:2 2 0  [0] 2 //62:0 1 3  [2] 3 //63:3 2 2  [0] 3 //64:1 0 3  [2] 3 //65:1 0 2  [2] 2 //66:2 1 2  [2] 2 //67:1 3 1  [1] 3 //68:1 2 3  [2] 3 //69:1 0 1  [2] 1 //70:2 0 3  [2] 3 //71:2 3 1  [1] 3 //72:3 2 3  [2] 3 //73:3 1 3  [2] 3 //74:1 0 0  [0] 1 //75:2 2 1  [1] 2 //76:2 2 3  [2] 3 //77:2 1 2  [0] 2 //78:2 3 3  [1] 3 //79:1 2 0  [1] 2 //80:1 0 3  [2] 3 //81:1 0 0  [0] 1 //82:0 0 1  [2] 1 //83:1 0 0  [0] 1 //84:2 1 0  [0] 2 //85:1 1 2  [2] 2 //86:0 0 0  [0] 0 //87:1 3 2  [1] 3 //88:1 0 2  [2] 2 //89:0 1 3  [2] 3 //90:3 0 2  [0] 3 //91:2 3 2  [1] 3 //92:1 1 2  [2] 2 //93:3 1 3  [0] 3 //94:2 2 2  [1] 2 //95:1 1 2  [2] 2 //96:1 1 1  [2] 1 //97:0 2 0  [1] 2 //98:3 3 1  [1] 3 //99:3 1 2  [0] 3 //

user: user-3
content: int n[3]={1,2,3}; 	int max; 	max=n[0];        	int count=0;     //初始方向0； 	for(int i=0;i<2;i++) 	{ 		if(n[i]<=n[i+1]) 			max=n[i+1]; 		count=i+1; 	} 	printf("%d\n%d\n",max,count);

user: user-4
content: 用for循环啊，就像求n个数最大值一样，在里面加一个相等时的分支，相等就随机选