杭电OJ基础100题2000-2020答案(C语言版)

2000.ASCII码排序

#include <stdio.h>
#include <stdlib.h>
int main(){
       char a=0,b=0,c=0,t=0;
       while(scanf(" %c%c%c ",&a,&b,&c)!=EOF){//主要是判断是否文件结束(常用于多组数据输入)
            //如果存在逆序的字符,就交换次序。
            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;
}

2001.计算两点间的距离

#include <stdio.h>
#include <math.h>//sqrt函数需引入的库函数
int main()
{
    double x1, x2, y1, y2, a;//取double是方便后面保留两位小数
    while (scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2) != EOF)
    {
        a = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
        printf("%.2lf\n", a);
    }
    return 0;
}

2002.计算球体积

#define PI 3.1415927
#include <stdio.h>
int main()
{
      double r,volume;
      while(scanf("%lf",&r) != EOF ){
             volume=PI*r*r*r*4/3;//体积公式V=4/3*PI*r*r*r;
             printf("%.3lf\n",volume);
      }
      return 0;
}

2003.求绝对值

#include <stdio.h>
#include <math.h>
int main()
{
        double a,sum;
        while(scanf("%lf",&a) != EOF)
        {
           sum=fabs(a);// double fabs(double a) math.h库中求绝对值的库函数
           printf("%.2lf\n",sum);
        }
        return 0;

}

2004.成绩转换

#include <stdio.h>
int main()
{
    int score;
    while(scanf("%d",&score) != EOF){
          if(score<0|score>100){//如果不属于0-100的范围就出错
            printf("Score is error!\n");
          }else if(score<60){//0-60
            printf("E\n");    
          }else if(score<70){//60-70
            printf("D\n");
          }else if(score<80){//70-80
            printf("C\n");
          }else if(score<90){//80-90
            printf("B\n");
          }else{//90-100
            printf("A\n");
          }
     
   }
   return 0;
}

2005.第几天?


                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值