杭电100题(一)

HDU-2000.ASCII码排序
Description:

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

Input:

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

Output:

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

SampleInput:

qwe
asd
zxc

SampleOutput:

e q w
a d s
c x z

Codes:
//#define LOCAL

#include <cstdio>

int main()
{
    #ifdef LOCAL
        freopen("E:\\Temp\\input.txt", "r", stdin);
        freopen("E:\\Temp\\output.txt", "w", stdout);
    #endif

    char a, b, c, p;

    while((p=scanf("%c%c%c\n", &a, &b, &c)) != EOF) {
        if(a > b) { p = a; a = b; b = p; }
        if(b > c) { p = b; b = c; c = p; }
        if(a > b) { p = a; a = b; b = p; }
        printf("%c %c %c\n", a, b, c);  
    }

    return 0;
}
HDU-2001.计算两点间的距离
Description:

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

Input:

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

Output:

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

SampleInput:

0 0 0 1
0 1 1 0

SampleOutput:

1.00
1.41

Codes:
//#define LOCAL

#include <cstdio>
#include <cmath>

int main()
{
    #ifdef LOCAL
        freopen("E:\\Temp\\input.txt", "r", stdin);
        freopen("E:\\Temp\\output.txt", "w", stdout);
    #endif

    double a, b, c, d, p;
    while(scanf("%lf%lf%lf%lf", &a, &b, &c, &d) != EOF) {
        p = sqrt(pow(c-a, 2)+pow(d-b, 2));
        printf("%.2f\n", p);
    }

    return 0;
}
HDU-2002.计算球体积
Description:

根据输入的半径值,计算球的体积。

Input:

输入数据有多组,每组占一行,每行包括一个实数,表示球的半径。

Output:

输出对应的球的体积,对于每组输入数据,输出一行,计算结果保留三位小数。

SampleInput:

1
1.5

SampleOutput:

4.189
14.137

Codes:
//const double PI = acos(-1.0);
//#define LOCAL

#include <cstdio>
#include <cmath>

int main()
{
    #ifdef LOCAL
        freopen("E:\\Temp\\input.txt", "r", stdin);
        freopen("E:\\Temp\\output.txt", "w", stdout);
    #endif

    double r, v;
    const double PI = 3.1415927;
    while(scanf("%lf", &r) != EOF) {
        v = PI*pow(r, 3)*4/3;
        printf("%.3f\n", v);
    }

    return 0;
}
HDU-2003.求绝对值
Description:

求实数的绝对值。

Input:

输入数据有多组,每组占一行,每行包含一个实数。

Output:

对于每组输入数据,输出它的绝对值,要求每组数据输出一行,结果保留两位小数。

SampleInput:

123
-234.00

SampleOutput:

123.00
234.00

Codes:
//#define LOCAL

#include <cstdio>
#include <cmath>

int main()
{
    #ifdef LOCAL
        freopen("E:\\Temp\\input.txt", "r", stdin);
        freopen("E:\\Temp\\output.txt", "w", stdout);
    #endif

    double a;
    while(scanf("%lf", &a) != EOF)
        printf("%.2f\n", fabs(a));

    return 0;
}
HDU-2004.成绩转换
Description:

输入一个百分制的成绩t,将其转换成对应的等级,具体转换规则如下:
90~100为A; 80~89为B; 70~79为C; 60~69为D; 0~59为E;

Input:

输入数据有多组,每组占一行,由一个整数组成。

Output:

对于每组输入数据,输出一行。如果输入数据不在0~100范围内,请输出一行:“Score is error!”。

SampleInput:

56
67
100
123

SampleOutput:

E
D
A
Score is error!

Codes:
//#define LOCAL

#include <cstdio>

int main()
{
    #ifdef LOCAL
        freopen("E:\\Temp\\input.txt", "r", stdin);
        freopen("E:\\Temp\\output.txt", "w", stdout);
    #endif

    int a;
    while(scanf("%d", &a) != EOF) {
        if(a>100 || a<0) printf("Score is error!\n");
        else if(a >= 90) printf("A\n");
        else if(a >= 80) printf("B\n");
        else if(a >= 70) printf("C\n");
        else if(a >= 60) printf("D\n");
        else printf("E\n");
    }

    return 0;
}
HDU-2005.第几天?
Description:

给定一个日期,输出这个日期是该年的第几天。

Input:

输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input,另外,可以向你确保所有的输入数据是合法的。

Output:

对于每组输入数据,输出一行,表示该日期是该年的第几天。

SampleInput:

1985/1/20
2006/3/12

SampleOutput:

20
71

Codes:
//#define LOCAL

#include <cstdio>

int a[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main()
{
    #ifdef LOCAL
        freopen("E:\\Temp\\input.txt", "r", stdin);
        freopen("E:\\Temp\\output.txt", "w", stdout);
    #endif

    int i, y, m, d, t;
    while(scanf("%d/%d/%d", &y, &m, &d) != EOF) {
        t = 0;
        for(i=0; i<m; ++i) t += a[i]; t += d; 
        if((!(y%4)&&y%100) || !(y%400)) if(m > 2) ++t;
        printf("%d\n", t);
    }

    return 0;
}
HDU-2006.求奇数的乘积
Description:

给你n个整数,求他们中所有奇数的乘积。

Input:

输入数据包含多个测试实例,每个测试实例占一行,每行的第一个数为n,表示本组数据一共有n个,接着是n个整数,你可以假设每组数据必定至少存在一个奇数。

Output:

输出每组数中的所有奇数的乘积,对于测试实例,输出一行。

SampleInput:

3 1 2 3
4 2 3 4 5

SampleOutput:

3
15

Codes:
//b = 2^n, a%b = a&b-1
//#define LOCAL

#include <cstdio>
#include <cmath>

int main()
{
    #ifdef LOCAL
        freopen("E:\\Temp\\input.txt", "r", stdin);
        freopen("E:\\Temp\\output.txt", "w", stdout);
    #endif

    int a, b, c, i;
    while(scanf("%d", &a) != EOF) {
        for(c=1, i=0; i<a; ++i) {
            scanf("%d", &b);
            if(b & 1) c *= b;
        }
        printf("%d\n", c);
    }

    return 0;
}
HDU-2007.平方和与立方和
Description:

给定一段连续的整数,求出他们中所有偶数的平方和以及所有奇数的立方和。

Input:

输入数据包含多组测试实例,每组测试实例包含一行,由两个整数m和n组成。

Output:

对于每组输入数据,输出一行,应包括两个整数x和y,分别表示该段连续的整数中所有偶数的平方和以及所有奇数的立方和。
你可以认为32位整数足以保存结果。

SampleInput:

1 3
2 5

SampleOutput:

4 28
20 152

Codes:
//pow(5, 3) = 124?
//#define LOCAL

#include <cstdio>

int main()
{
    #ifdef LOCAL
        freopen("E:\\Temp\\input.txt", "r", stdin);
        freopen("E:\\Temp\\output.txt", "w", stdout);
    #endif

    int a, b, i, p, q;
    while(scanf("%d%d", &a, &b) != EOF) {
        if(a > b) { i = a; a = b; b = i; }
        for(p=q=0, i=a; i<=b; ++i)  
            i&1 ? q+=i*i*i : p+=i*i;
        printf("%d %d\n", p, q);
    }
    
    return 0;
}
HDU-2008.数值统计
Description:

统计给定的n个数中,负数、零和正数的个数。

Input:

输入数据有多组,每组占一行,每行的第一个数是整数n(n<100),表示需要统计的数值的个数,然后是n个实数;如果n=0,则表示输入结束,该行不做处理。

Output:

对于每组输入数据,输出一行a,b和c,分别表示给定的数据中负数、零和正数的个数。

SampleInput:

6 0 1 2 3 -1 0
5 1 2 3 4 0.5
0

SampleOutput:

1 2 3
0 0 5

Codes:
//#define LOCAL

#include <cstdio>

int main()
{
    #ifdef LOCAL
        freopen("E:\\Temp\\input.txt", "r", stdin);
        freopen("E:\\Temp\\output.txt", "w", stdout);
    #endif

    int n, a, b, c;
    double x;
    while(scanf("%d", &n), n) {
        a = b = c = 0;
        while(n--) {
            scanf("%lf", &x);
            if(x < 0) ++a;
            else if(x > 0) ++c;
            else ++b;
        }
        printf("%d %d %d\n", a, b, c);
    }

    return 0;
}
HDU-2009.求数列的和
Description:

数列的定义如下:
数列的第一项为n,以后各项为前一项的平方根,求数列的前m项的和。

Input:

输入数据有多组,每组占一行,由两个整数n(n<10000)和m(m<1000)组成,n和m的含义如前所述。

Output:

对于每组输入数据,输出该数列的和,每个测试实例占一行,要求精度保留2位小数。

SampleInput:

81 4
2 2

SampleOutput:

94.73
3.41

Codes:
//#define LOCAL

#include <cstdio>
#include <cmath>

int main()
{
    #ifdef LOCAL
        freopen("E:\\Temp\\input.txt", "r", stdin);
        freopen("E:\\Temp\\output.txt", "w", stdout);
    #endif 

    int m;
    double a, n;
    while(scanf("%lf%d", &n, &m) != EOF) {
        for(a=0; m--; n=sqrt(n)) a += n;
        printf("%.2f\n", a);
    }

    return 0;
}

转载于:https://www.cnblogs.com/VincentValentine/p/7468056.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值