2000 ASCII码排序
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Problem Description
输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。
Input
输入数据有多组,每组占一行,有三个字符组成,之间无空格。
Output
对于每组输入数据,输出一行,字符中间用一个空格分开。
Sample Input
qwe
asd
zxc
Sample Output
e q w
a d s
c x z
Submit
#include<stdio.h>
int main()
{
char a[3], temp;
while(scanf("%s", &a) != EOF)
{
if(a[0] > a[1]){
temp = a[0];
a[0] = a[1];
a[1] = temp;
}
if(a[0] > a[2]){
temp = a[0];
a[0] = a[2];
a[2] = temp;
}
if(a[1] > a[2]){
temp = a[1];
a[1] = a[2];
a[2] = temp;
}
printf("%c %c %c\n", a[0], a[1], a[2]);
}
return 0;
}
2001 计算两点间的距离
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Problem Description
输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离。
Input
输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔开。
Output
对于每组输入数据,输出一行,结果保留两位小数。
Sample Intput
0 0 0 1
0 1 1 0
Sample Output
1.00
1.41
Submit
#include<stdio.h>
#include<math.h>
int main()
{
double x1, y1, x2, y2;
double dis;
while(scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2) != EOF)
{
dis = sqrt((y1 - y2)*(y1 - y2) + (x1- x2)*(x1- x2) );
printf("%.2lf\n", dis);
}
return 0;
}
2002 计算球体积
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Problem Description
根据输入的半径值,计算球的体积。
Intput
输入数据有多组,每组占一行,每行包括一个实数,表示球的半径。
Output
输出对应的球的体积,对于每组输入数据,输出一行,计算结果保留三位小数。
Sample Intput
1
1.5
Sample Output
4.189
14.137
Submit
#include<stdio.h>
#include<math.h>
#define PI 3.1415927
int main()
{
double r;
double V;
while(~scanf("%lf", &r))
{
V = 4*PI*r*r*r/3;
printf("%.3lf\n", V);
}
}