游客 Signup | Login
中文 | En

1244 - C语言10.14

输入3个整数,按从小到大的顺序输出。要求使用指针的方法进行处理。

Input

3个用空格隔开的整数。

Output

按从小到大的顺序输出这3个整数,用空格隔开。

请注意行尾输出换行。

Examples

Input

25 39 16

Output

16 25 39

Solution C

#include<stdio.h>
void fun(int *p, int *q,int *r)
{
	int x,y,z;
	x=*p<*q?*p:*q;
	x=x<*r?x:*r;
	z=*p>*q?*p:*q;
	z=z>*r?z:*r;
	y=*p+*q+*r-x-z;
	printf("%d %d %d\n",x,y,z);

}
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	fun(&a,&b,&c);
	return 0;
}

Solution C++

#include <stdio.h>
int main() {
	int *pa, *pb, *pc, *t;
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	pa = &a; pb = &b; pc = &c;
	if (*pa > *pb) {
		t = pa; pa = pb; pb = t;
	}
	if (*pa > *pc) {
		t = pa; pa = pc; pc = t;
	}
	if (*pb > *pc) {
		t = pb; pb = pc; pc = t;
	}
	printf("%d %d %d\n", *pa, *pb, *pc);
	return 0;
}

Time Limit 1 second
Memory Limit 32 MB
Discuss Stats
上一题 下一题