3254 - 例题4-2 比较交换实数值

通过次数

0

提交次数

0

时间限制 : 1 秒 内存限制 : 12 MB

从键盘输入2个实数,按照代数值由小到大的顺序输出这两个数。

题目输入

用空格分隔的两个实数。

题目输出

从小到大输出这两个实数,中间以空格来分隔,小数在前,大数在后。

小数点后保留2位小数。

末尾输出换行符。

输入/输出样例

输入格式

3.6 -2.3

输出格式

-2.30 3.60

C语言解答

#include<stdio.h>
int main ()
{
	float a,b,m;
	scanf("%f%f",&a,&b);
	if (a>b)
	{m=a;a=b;b=m;}
	printf("%.2f %.2f\n",a,b);
	getchar();
	getchar();
	return 0;
}

C++解答

#include <cstdio>
#include <cmath>
int main (void)
{
	double a,b;
	scanf("%lf%lf",&a,&b);
	if(a<b)
		printf("%.2f %.2f\n",a,b);
	else printf("%.2f %.2f\n",b,a);
	return 0;
}

Python解答

# coding=utf-8
s = input(). split()
print(format(min(map(float, s)), ".2f"), format(max(map(float, s)), ".2f"))