# 杭电acm答案无敌版

2012 素数判定................................................................................................................................ 34 2014 青年歌手大奖赛_评委会打分362017 字 符 串 统 计 ........................................................................................................................................................ 42 2019 数列有序! .............................................................................................................................. 43 2020 绝对值排序............................................................................................................................ 45 2033 人见人爱 A+B ....................................................................................................................... 48 2039 三角形.................................................................................................................................... 50 2040 亲和数.................................................................................................................................... 51

1001 Sum Problem

Problem Description
Hey, welcome to HDOJ(Hangzhou Dianzi University Online Judge). In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.

Input
The input will consist of a series of integers n, one integer per line.

Output
For each case, output SUM(n) in one line, followed by a blank line. You may assume the result will be in the range of 32-bit signed integer.

Sample Input
1 100

Sample Output
1 5050

Author
DOOM III

main() { int n,i,sum; sum=0; while((scanf("%d",&n)!=-1)) { sum=0; for(i=0;i<=n;i++) sum+=i;

printf("%d\n\n",sum); } }

1089

A+B for Input-Output Practice (I)

Problem Description
Your task is to Calculate a + b. Too easy?! Of course! I specially designed the problem for acm beginners. You must have found that some problems have the same titles with this one, yes, all these problems were designed for the same aim.

Input
The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.

Output
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.

Sample Input
1 5 10 20

Sample Output
6 30

Author
lcy

Recommend
JGShining

1090 A+B for Input-Output Practice (II)
Problem Description

Input
Input contains an integer N in the first line, and then N lines follow. Each line consists of a pair of integers a and b, separated by a space, one pair of integers per line.

Output
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.

Sample Input
2 1 5 10 20

Sample Output
6 30

Author
lcy

Recommend
JGShining

1091 A+B for Input-Output Practice (III)
Problem Description

Input
Input contains multiple test cases. Each test case contains a pair of integers a and b, one pair of integers per line. A test case containing 0 0 terminates the input and this test case is not to be processed.

Output
For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.

Sample Input
1 5 10 20 0 0

Sample Output
6 30

Author
lcy

Recommend
JGShining

1092 A+B for Input-Output Practice (IV)
Problem Description

Input
Input contains multiple test cases. Each test case contains a integer N, and then N integers follow in the same line. A test case starting with 0 terminates the input and this test case is not to be processed.

Output
For each group of input integers you should output their sum in one line, and with one line of output for each line in input.

Sample Input
4 1 2 3 4 5 1 2 3 4 5 0

Sample Output
10

15

Author
lcy

Recommend
JGShining

1093

A+B for Input-Output Practice (V)

Problem Description

Input
Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.

Output
For each group of input integers you should output their sum in one line, and with one line of output for each line in input.

Sample Input
2 4 1 2 3 4 5 1 2 3 4 5

Sample Output
10 15

Author
lcy

1094 A+B for Input-Output Practice (VI)
Problem Description

Input
Input contains multiple test cases, and one case one line. Each case starts with an integer N, and then N integers follow in the same line.

Output
For each test case you should output the sum of N integers in one line, and with one line of output for each line in input.

Sample Input
4 1 2 3 4 5 1 2 3 4 5

Sample Output
10 15

Author
lcy

Recommend
JGShining

[ Copy to Clipboard ] [ Save to File]

1095 A+B for Input-Output Practice (VII)
Problem Description

Input
The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.

Output
For each pair of input integers a and b you should output the sum of a and b, and followed by a blank line.

Sample Input
1 5 10 20

Sample Output
6 30

Author
lcy

Recommend
JGShining

1096 A+B for Input-Output Practice (VIII)
Problem Description

Input
Input contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.

Output
For each group of input integers you should output their sum in one line, and you must note that there is a blank line between outputs.

Sample Input
3 4 1 2 3 4 5 1 2 3 4 5 3 1 2 3

Sample Output
10 15 6

Author
lcy

Recommend
JGShining

2000 ASCII 码排序
Problem Description

Input

Output

Sample Input
qwe asd zxc

Sample Output
e q w a d s c x z

Author
lcy

Source
C 语言程序设计练习（一）

Recommend
JGShining

else { if(c>=b) printf("%c %c %c\n",a,b,c); else if(c>=a) printf("%c %c %c\n",a,c,b); else if(a>c) printf("%c %c %c\n",c,a,b); }

} }

2001 计算两点间的距离
Problem Description

Input

Output

Sample Input
0 0 0 1 0 1 1 0

Sample Output
1.00 1.41

Author
lcy

Source
C 语言程序设计练习（一）

Recommend
JGShining

2002 计算球体积
Problem Description

Input

Output

Sample Input
1 1.5

Sample Output
4.189 14.137 Hint #define PI 3.1415927

Author
lcy

Source
C 语言程序设计练习（一）

Recommend
JGShining

2003 求绝对值
Problem Description

Input

Output

Sample Input
123 -234.00

Sample Output
123.00 234.00

Author
lcy

Source
C 语言程序设计练习（一）

Recommend
JGShining

2004 成绩转换

Problem Description

Input

Output

Sample Input
56 67 100 123

Sample Output
E D A Score is error!

Author
lcy

Source
C 语言程序设计练习（一）

Recommend
JGShining

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

2005 第几天？
Problem Description

Input

Output

Sample Input
1985/1/20 2006/3/12

Sample Output
20 71

Author
lcy

Source
C 语言程序设计练习（一）

Recommend
JGShining

if(e==0) { if(f==0) d=1+d; else d=d; } else if(g=0) d=d+1; else d=d; printf("%d\n",d); } }

2006 求奇数的乘积
Problem Description

Input

Output

Sample Input
3 1 2 3 4 2 3 4 5

Sample Output
3 15

Author
lcy

Source
C 语言程序设计练习（一）

Recommend
JGShining

2007 平方和与立方和
Problem Description

Input

Output

Sample Input
1 3 2 5

Sample Output
4 28 20 152

Author
lcy

Source
C 语言程序设计练习（一）

Recommend
JGShining

2008 数值统计

Problem Description

Input

Output

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

Sample Output
1 2 3 0 0 5

Author
lcy

Source
C 语言程序设计练习（二）

Recommend
JGShining

for(i=0;i<n;i++) scanf("%lf",&a[i]); b1=b2=b3=0; for(i=0;i<n;i++) { if(a[i]<0) b1++; else if(a[i]==0) b2++; else b3++; } printf("%d %d %d\n",b1,b2,b3); } }

2009 求数列的和
Problem Description

Input

Output

Sample Input
81 4 2 2

Sample Output
94.73 3.41

Author
lcy

Source
C 语言程序设计练习（二）

Recommend
JGShining

2010 水仙花数
Problem Description

Input

Output

Sample Input
100 120 300 380

Sample Output
no 370 371

Author
lcy

Source
C 语言程序设计练习（二）

Recommend
JGShining

c=i%10; s=a*a*a+b*b*b+c*c*c; if(i==s) { if(d!=0) printf(" "); printf("%d",i); d=d+1; j=j+1; } } if(j==1) printf("no\n"); else printf("\n"); } }

2011 多项式求和
Problem Description

Input

Output

Sample Input
2 1 2

Sample Output
1.00 0.50

Author
lcy

Source
C 语言程序设计练习（二）

Recommend
JGShining

2012 素数判定

Problem Description

Input

Output

Sample Input
0 1 0 0

Sample Output
OK

Author
lcy

Source
C 语言程序设计练习（二）

Recommend
JGShining

for(i=x;i<=y;i++) { k=i*i+i+41; for(j=2;j<k;j++) { d=k%j; if(d==0) w++; } } if(w==0) printf("OK\n"); else printf("Sorry\n");

} }

2014 青年歌手大奖赛_评委会打分
Problem Description

Input

Output

Sample Input
3 99 98 97 4 100 99 98 97

Sample Output
98.00 98.50

Author
lcy

Source
C 语言程序设计练习（三）

Recommend
lcy

w=(w-s-b)/(k-2); printf("%.2lf\n",w); } }

2015 偶数求和
Problem Description

Input

Output

Sample Input
3 2 4 2

Sample Output
3 6 3 7

Author
lcy

Source
C 语言程序设计练习（三）

Recommend
lcy

main() { int n,m,a,b,i,j,k,w,l,e,s,d,r; while(scanf("%d%d",&n,&m)!=EOF) { s=0; e=0; l=0; if(n<=m) { for(i=0;i<n;i++) { s=s+2; e=e+s; k=e/n; } printf("%d\n",k); } else { w=n%m; r=0; for(i=1;i<=n-w;i++) { s=s+2; l=l+s; e=e+s; if(i%m==0) { k=e/m; e=0; if(r) printf(" "); printf("%d",k); r=r+1; } } s=0; if(w!=0) { for(j=0;j<n;j++) { s=s+2;

e=e+s; } d=e-l; k=d/w; printf(" "); printf("%d",k); } printf("\n"); } } }

2016 数据的交换输出
Problem Description

Input

Output

Sample Input
4 2 1 3 4 5 5 4 3 2 1 0

Sample Output
1 2 3 4 1 4 3 2 5

Author
lcy

Source
C 语言程序设计练习（三）

Recommend
lcy

2017 字符串统计
Problem Description

Input

Output

Sample Input
2 asdfasdf123123asdfasdf asdf111111111asdfasdfasdf

Sample Output
6 9

Author
lcy

for(j=0;s[j]!='\0';j++) { if((s[j]<='9')&&(s[j]>='0')) a=a+1; } printf("%d\n",a); } } }

2019 数列有序!
Problem Description

Input

Output

Sample Input
3 3 1 2 4 0 0

Sample Output
1 2 3 4

Author
lcy

Source
C 语言程序设计练习（三）

Recommend
lcy

printf("%d",a[j]); } } printf("\n"); scanf("%d%d",&n,&m); } }

2020 绝对值排序
Problem Description

Input

Output

Sample Input
3 3 -4 2 4 0 1 2 -3 0

Sample Output
-4 3 2 -3 2 1 0

Author
lcy

Source
C 语言程序设计练习（三）

Recommend
lcy

2021 发工资咯： ）

Problem Description

Input

Output

Sample Input
3 1 2 3 0

Sample Output
4

Author
lcy

Source
C 语言程序设计练习（四）

Recommend
lcy

main() { int n,m,a,b,c,d,e,f,i,j,k; while(scanf("%d",&n)!=EOF&&n!=0) { k=0; for(i=0;i<n;i++) { scanf("%d",&m); a=m/100; b=m%100/50; c=m%100%50/10; d=m%100%50%10/5; e=m%100%50%10%5/2; f=m%100%50%10%5%2; k=k+a+b+c+d+e+f; } printf("%d\n",k); } }

2033 人见人爱 A+B
Problem Description
HDOJ 上面已经有 10 来道 A+B 的题目了，相信这些题目曾经是大家的最爱，希望今天的这 个 A+B 能给大家带来好运，也希望这个题目能唤起大家对 ACM 曾经的热爱。 这个题目的 A 和 B 不是简单的整数，而是两个时间，A 和 B 都是由 3 个整数组成，分别表 示时分秒，比如，假设 A 为 34 45 56，就表示 A 所表示的时间是 34 小时 45 分钟 56 秒。

Input

Output

Sample Input
2 1 2 3 4 5 6 34 45 56 12 23 34

Sample Output
5 7 9 47 9 30

Author
lcy

Source
ACM 程序设计期末考试（2006/06/07）

Recommend
lcy

s=s+1; } a=a+s; printf("%d %d %d\n",a,b,c); } } }

2039 三角形
Problem Description

Input

Output

Sample Input
2 1 2 3 2 2 2

Sample Output
NO YES

Author
linle

Source
2005 实验班短学期考试

Recommend
lcy

2040 亲和数
Problem Description

Input

Output

Sample Input
2 220 284 100 200

Sample Output
YES NO

Author
linle

Source
2005 实验班短学期考试

Recommend
lcy

}

### 杭电acm的利用

(非常好并且非常重要的题,一定不要嫌麻烦,全做一遍再看答案)、12、17 P170 ...大家可以按照我发在 blog 上面的《杭电 ACM 阶段理工大版》来刷题~~~刷完省...