“21好习惯“第一期-7

ASCII码排序
 

Problem Description
输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。
 

Input
输入数据有多组,每组占一行,有三个字符组成,之间无空格。
 

Output
对于每组输入数据,输出一行,字符中间用一个空格分开。
 

Sample Input
 
 
qwe asd zxc
 

Sample Output
 
 
e q w a d s c x z
 
#include <stdio.h>
int main()
{
char a,b,c,t;
while(~scanf("%c%c%c",&a,&b,&c))
{
getchar();
if(a>b)
    {
        t=a;a=b;b=t;
}
if(a>c)
  {
    t=a;a=c;c=t;
}
if(b>c)
    {
        t=b;b=c;c=t;
}
printf("%c %c %c\n",a,b,c);
}
return 0;
}


 

计算两点间的距离

 

Problem Description
输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离。
 

Input
输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔开。
 

Output
对于每组输入数据,输出一行,结果保留两位小数。
 

Sample Input
 
 
0 0 0 1 0 1 1 0
 

Sample Output
 
 
1.00 1.41
#include <stdio.h>
#include <math.h>
int main()
{
       float x1,x2,y1,y2,l;
       while(~scanf("%f%f%f%f",&x1,&y1,&x2,&y2))
{
       l=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
      printf("%.2f\n",l);
}
      return 0;
}

计算球体积



 
Problem Description
根据输入的半径值,计算球的体积。
 
 
Input
输入数据有多组,每组占一行,每行包括一个实数,表示球的半径。
 
 
Output
输出对应的球的体积,对于每组输入数据,输出一行,计算结果保留三位小数。
 
 
Sample Input
 
   
1 1.5
 
 
Sample Output
 
   
4.189 14.137
 
 
Hint

#define PI 3.1415927

#include<stdio.h>
#include<math.h>
#define PI 3.1415927
int main()
{
   double r, v;
   while(scanf("%lf", &r)!=EOF)
    {  

        v = 4.0 / 3.0 * PI*r*r*r;
        printf("%.3f\n", v);
        
    }    
   return 0;
}

求绝对值



 
Problem Description
求实数的绝对值。
 
 
Input
输入数据有多组,每组占一行,每行包含一个实数。
 
 
Output
对于每组输入数据,输出它的绝对值,要求每组数据输出一行,结果保留两位小数。
 
 
Sample Input
 
   
123 -234.00
 
 
Sample Output
 
   
123.00 234.00

#include <stdio.h>
#include <math.h>
int main()
{
      double a;
      while(~scanf("%lf",&a)){
      printf("%.2lf\n",fabs(a));
}
      return 0;
}

成绩转换

 
Problem Description
输入一个百分制的成绩t,将其转换成对应的等级,具体转换规则如下:
90~100为A;
80~89为B;
70~79为C;
60~69为D;
0~59为E;
 
 
Input
输入数据有多组,每组占一行,由一个整数组成。
 
 
Output
对于每组输入数据,输出一行。如果输入数据不在0~100范围内,请输出一行:“Score is error!”。
 
 
Sample Input
 
   
56 67 100 123
 
 
Sample Output
 
   
E D A Score is error!
#include <stdio.h>
int main()
{
    int a;
    while(~scanf("%d",&a))
{
if(a>=90&&a<=100)
    {
        printf("A\n");
}
else if(a>=80&&a<=89)
    {
        printf("B\n");
}
else if(a>=70&&a<=79)
    {
        printf("C\n");
}
else if(a>=60&&a<=69)
    {
        printf("D\n");
}
else if(a>=0&&a<=59)
    {
        printf("E\n");
}
else
    printf("Score is error!\n");
}
return 0;
}

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值