首页 > 其他 > 详细

hdu2000~2004

时间:2015-02-12 07:01:58      阅读:277      评论:0      收藏:0      [点我收藏+]

hdu2000:

把三个字符按ASCII码排序,昂反正字符也算int型,直接比呗,注意读掉回车就酱水过

#include<stdio.h>
int main()
{
    char a,b,c,t;
    while (scanf("%c%c%c",&a,&b,&c)!=EOF)
    {
        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;
}

hdu2001:
计算两点间距离,注意读入的数据就是浮点型了,水过

#include<stdio.h>
#include<math.h>
int main()
{
    double x1,y1,x2,y2,d;
    while (scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2)!=EOF)
    {
        d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
        printf("%.2lf\n",d);
    }
    return 0;
}

hdu2002:
计算球体积,公式水过就好。

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

hdu2003:
求绝对值,注意读入是浮点型,之后用函数也好用我那时候用的土办法也好,水过就好~

#include<stdio.h>
int main()
{
    double a;
    while (scanf("%lf",&a)!=EOF)
    {
        if (a>=0) printf("%.2lf\n",a);
        else printf("%.2lf\n",-a);
    }
    return 0;
}

hdu2004:
成绩转换,六个if水过,出题人你开心就好```

#include<stdio.h>
int main()
{
    int t;
    while (scanf("%d",&t)!=EOF)
    {
        if (90<=t&&t<=100) printf("A\n");
        if (80<=t&&t<=89) printf("B\n");
        if (70<=t&&t<=79) printf("C\n");
        if (60<=t&&t<=69) printf("D\n");
        if (0<=t&&t<=59) printf("E\n");
        if (100<t||t<0) printf("Score is error!\n");
    }
    return 0;
}

hdu2000~2004

原文:http://www.cnblogs.com/cenariusxz/p/4287259.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!