杭電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;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM