Sunteți pe pagina 1din 55

...............................................................................................................................................

1
1001........................................................................................................................................1
1010504134..................................................................................................................................2
1001 Sum Problem..............................................................................................................................3
1089 A+B for Input-Output Practice (I).............................................................................................5
1090 A+B for Input-Output Practice (II)...........................................................................................7
1091 A+B for Input-Output Practice (III)..........................................................................................9
1092 A+B for Input-Output Practice (IV).........................................................................................10
1093 A+B for Input-Output Practice (V).........................................................................................12
1094 A+B for Input-Output Practice (VI)........................................................................................14
1095 A+B for Input-Output Practice (VII).......................................................................................16
1096 A+B for Input-Output Practice (VIII).....................................................................................17
2000 ASCII ................................................................................................................................18
2001 ...............................................................................................................................20
2002 ..............................................................................................................................21
2003 .........................................................................................................................................22
2004 .........................................................................................................................................24
2005 .........................................................................................................................................25
2006 ..........................................................................................................................27
2007 .................................................................................................................................28
2008 ..................................................................................................................................30
2009 ..............................................................................................................................31
2010 ..................................................................................................................................32
2011 ......................................................................................................................................34
2012 ..................................................................................................................................36
2014 _...................................................................................................................37
2015 ..................................................................................................................................39
2016 .................................................................................................................................41
2017 ..............................................................................................................................43
2019 !.......................................................................................................................................44
2020 .....................................................................................................................................46
2021 ....................................................................................................................................48
2033 A+B................................................................................................................................49
2039 ...........................................................................................................................................51
2040 ......................................................................................................................................52

1001

1010504134

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

#include<stdio.h>
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


#include<stdio.h>
main()
{
int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
printf("%d\n",a+b);
}

1090 A+B for Input-Output


Practice (II)
Problem Description
Your task is to Calculate a + b.

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


#include<stdio.h>
#define M 1000
void main()
{
int a ,b,n,j[M],i;
//printf("please input n:\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d%d",&a,&b);
//printf("%d %d",a,b);
j[i]=a+b;
}
i=0;
while(i<n)
{
printf("%d",j[i]);
i++;
printf("\n");
}
}

1091 A+B for Input-Output


Practice (III)
Problem Description
Your task is to Calculate a + b.

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


#include<stdio.h>
main()
{
int a,b;
scanf("%d %d",&a,&b);
while(!(a==0&&b==0))
{
printf("%d\n",a+b);
scanf("%d %d",&a,&b);
}
}

1092 A+B for Input-Output


Practice (IV)
Problem Description
Your task is to Calculate the sum of some integers.

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

#include <stdio.h>
int main()
{
int n,sum,i,t;
while(scanf("%d",&n)!=EOF&&n!=0)
{
sum=0;
for(i=0;i<n;i++)
{
scanf("%d",&t);
sum=sum+t;
}
printf("%d\n",sum);
}
}

1093 A+B for Input-Output


Practice (V)
Problem Description
Your task is to calculate the sum of some integers.

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


#include<stdio.h>
main()
{
int n,a,b,i,j,sum;
sum=0;
while(scanf("%d\n",&n)!=-1)
{
for(i=0;i<n;i++)
{
scanf("%d",&b);
for(j=0;j<b;j++)
{
scanf("%d",&a);
sum+=a;
}
printf("%d\n",sum);
sum=0;
}
}
}

1094 A+B for Input-Output


Practice (VI)
Problem Description
Your task is to calculate the sum of some integers.

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


#include<stdio.h>
main()
{
int n,a,b,i,j,sum;
sum=0;
while(scanf("%d\n",&n)!=-1)
{
for(j=0;j<n;j++)
{
scanf("%d",&a);
sum+=a;
}
printf("%d\n",sum);
sum=0;
}
}
[ Copy to Clipboard ]

[ Save to File]

1095 A+B for Input-Output


Practice (VII)
Problem Description
Your task is to Calculate a + b.

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


#include<stdio.h>
main()
{
int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
printf("%d\n\n",a+b);
}

1096 A+B for Input-Output


Practice (VIII)
Problem Description
Your task is to calculate the sum of some integers.

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

int main()
{
int a,b,i,j,l[1000],k;
scanf("%d",&i);
getchar();
for(j=1;j<=i;j++)
l[j]=0;
for(j=1;j<=i;j++)
{
scanf("%d",&a);
getchar();
for(k=1;k<=a;k++)
{
scanf("%d",&b);
getchar();
l[j]+=b;
}
}
for(j=1;j<=i-1;j++)
printf("%d\n\n",l[j]);
printf("%d\n",l[i]);
}

2000 ASCII
Problem Description
ASCII

Input

Output

Sample Input
qwe
asd
zxc

Sample Output
e q w
a d s
c x z

Author
lcy

Source
C

Recommend
JGShining

#include<stdio.h>
main()
{
char a,b,c,d;
while(scanf("%c %c %c",&a,&b,&c)!=EOF)
{
getchar();
if(a>=b)
{
if(c>=a)
printf("%c %c %c\n",b,a,c);
else if(b>=c)
printf("%c %c %c\n",c,b,a);
else if(b<c)
printf("%c %c %c\n",b,c,a);

}
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
X1,Y1,X2,Y2,

Input
4 x1,y1,x2,y2,

Output

Sample Input
0 0 0 1
0 1 1 0

Sample Output
1.00
1.41

Author

lcy

Source
C

Recommend
JGShining

#include<stdio.h>
#include<math.h>
main()
{
double a,b,c,d,s;
while(scanf("%lf %lf %lf %lf",&a,&b,&c,&d)!=EOF)
{
s=sqrt((a-c)*(a-c)+(b-d)*(b-d));
printf("%.2lf\n",s);
}
}

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

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

2003
Problem Description

Input

Output

Sample Input
123
-234.00

Sample Output
123.00
234.00

Author
lcy

Source
C

Recommend
JGShining

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

2004
Problem Description
t
90~100 A;
80~89 B;
70~79 C;
60~69 D;
0~59 E;

Input

Output
0~100 Score is

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
YYYY/MM/DD sample input ,

Output

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

Sample Output
20
71

Author
lcy

Source
C

Recommend
JGShining

#include<stdio.h>
main()
{
int a,b,c,d,e,f,g;
while(scanf("%d/%d/%d",&a,&b,&c)!=EOF)
{
if(b==1)
d=c;
else if(b==2)
d=31+c;
else if(b==3)
d=31+28+c;
else if(b==4)
d=31+28+31+c;
else if(b==5)
d=31+31+28+30+c;
else if(b==6)
d=31+28+31+30+31+c;
else if(b==7)
d=31+28+31+30+31+30+c;
else if(b==8)
d=31+28+31+30+31+30+31+c;
else if(b==9)
d=31+28+31+30+31+30+31+31+c;
else if(b==10)
d=31+28+31+30+31+30+31+31+30+c;
else if(b==11)
d=31+28+31+30+31+30+31+31+30+31+c;
else if(b==12)
d=31+28+31+30+31+30+31+31+30+31+c+30;

e=a%100;
f=a%400;
g=a%4;
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
n

Input
n
n n

Output

Sample Input
3 1 2 3
4 2 3 4 5

Sample Output
3
15

Author
lcy

Source
C

Recommend
JGShining

#include<stdio.h>
main()
{
int n,s,i,a;
while(scanf("%d",&n)!=EOF)
{
s=1;
for(i=0;i<n;i++)
{
scanf("%d",&a);
if(a%2==1)
s=s*a;
else ;
}
printf("%d\n",s);
}
}

2007
Problem Description

Input
m n

Output
x y

32

Sample Input
1 3
2 5

Sample Output
4 28
20 152

Author
lcy

Source
C

Recommend
JGShining

#include<stdio.h>
int main()
{
int sum1,sum2,n,i,m,t;
while(scanf("%d%d",&m,&n)!=EOF)
{
sum1=sum2=0;
if(m>n){t=m;m=n;n=t;}
for(i=m;i<=n;i++)
{
if(i%2==0) sum1+=(i*i);
else sum2+=(i*i*i);
}
printf("%d %d\n",sum1,sum2);
}
return 0;

2008
Problem Description
n

Input
nn<100
n n=0

Output
a,b c

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

#include<stdio.h>
int main()

{
int n,i,b1,b2,b3;
double a[101];
while(scanf("%d",&n)!=EOF && n!=0)
{
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

n m

Input
nn<10000 m(m<1000)n m

Output
2

Sample Input
81 4
2 2

Sample Output
94.73
3.41

Author
lcy

Source
C

Recommend
JGShining

#include<stdio.h>
#include<math.h>
main()
{
double n,m,s,w,i;
while(scanf("%lf%lf",&n,&m)!=EOF)
{
s=n;
for(i=1;i<m;i++)
{
n=sqrt(n);
s=s+n;
}
printf("%.2lf\n",s);
}
}

2010
Problem Description

153=1^3+5^3+3^3

Input
m n100<=m<=n<=999

Output

m, n
;
no;

Sample Input
100 120
300 380

Sample Output
no
370 371

Author
lcy

Source
C

Recommend
JGShining

#include<stdio.h>
main()
{
int m,n,i,w,a,b,c,j,s,d;
while(scanf("%d %d",&n,&m)!=EOF)
{
d=0;
j=1;
if(m>n)
{
w=m;
m=n;
n=w;

}
else ;
for(i=m;i<=n;i++)
{
a=i/100;
b=i/10%10;
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

1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 + ...


n

Input
2 mm<100
m ( n,n<1000 n

Output
n n
2

Sample Input
2
1 2

Sample Output
1.00
0.50

Author
lcy

Source
C

Recommend
JGShining

#include<stdio.h>
#include<math.h>
main()
{
double m,n,i,s,j,k,a;
while(scanf("%lf",&m)!=EOF)
{
for(i=0;i<m;i++)
{
s=0;
scanf("%lf",&n);
for(j=1;j<=n;j++)
s=s+1/j*pow(-1,j+1);
printf("%.2lf\n",s);
}
}

2012
Problem Description
n^2+n+41 n x,y x,y(-39<=x<y<=50)

Input
xy x=0,y=0

Output
"OK",Sorry,

Sample Input
0 1
0 0

Sample Output
OK

Author
lcy

Source
C

Recommend
JGShining

#include<stdio.h>

main()
{
int x,y,i,j,s,k,w,d;
while(scanf("%d%d",&x,&y)==2&&(x!=0||y!=0))
{
w=0;
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
n(2<n<100)
n

Output

Sample Input
3 99 98 97
4 100 99 98 97

Sample Output
98.00
98.50

Author
lcy

Source
C

Recommend
lcy

#include<stdio.h>
int main()
{
int n,s,a[100],i,k,b;
double w;
while(scanf("%d",&n)!=EOF)
{
k=0;
w=0;
s=0;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
k++;
b=a[0];
w=w+a[i];
}
for(i=0;i<k;i++)
{

if(a[i]>s)
s=a[i];
}
for(i=1;i<k;i++)
{
if(b>a[i])
b=a[i];
}
w=(w-s-b)/(k-2);
printf("%.2lf\n",w);
}
}

2015
Problem Description
n(n<=100) 2
m m

Input
n mn m

Output

Sample Input
3 2
4 2

Sample Output
3 6
3 7

Author
lcy

Source

Recommend
lcy

#include<stdio.h>
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
n(n<100)

Input
n
n n=0

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

#include<stdio.h>
main()
{
int n,a[100],i,j,k,s,w;
while(scanf("%d",&n)!=EOF&&n!=0)
{
j=0;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
k=a[0];
}
for(i=0;i<n;i++)
{
if(k>a[i])
{
k=a[i];
j=i;
}
}
w=a[0];
a[0]=k;
a[j]=w;

for(i=0;i<n;i++)
{
printf("%d",a[i]);
if(n-i!=1)
printf(" ");
}
printf("\n");
}
}

2017
Problem Description

Input
n n

Output

Sample Input
2
asdfasdf123123asdfasdf
asdf111111111asdfasdfasdf

Sample Output
6
9

Author
lcy

#include<stdio.h>
main()

{
int n,i,j,a;
char s[1000];
while(scanf("%d",&n)!=EOF)
{
getchar();
for(i=0;i<n;i++)
{
gets(s);
a=0;
for(j=0;s[j]!='\0';j++)
{
if((s[j]<='9')&&(s[j]>='0'))
a=a+1;
}
printf("%d\n",a);
}
}
}

2019 !
Problem Description
n(n<=100) x

Input
n m
n n m 0

Output

Sample Input
3 3
1 2 4
0 0

Sample Output
1 2 3 4

Author
lcy

Source
C

Recommend
lcy

#include<stdio.h>
main()
{
int n,m,a[100],b[100],i,j,k,s,w,d;
scanf("%d%d",&n,&m);
while(!(n==0&&m==0))
{
w=0;
for(i=0;i<n;i++)
scanf("%d",&a[i]);
s=a[0];
if(m<s)
{
printf("%d",m);
for(j=0;j<n;j++)
{
printf(" ");
printf("%d",a[j]);
}
}
else
{
for(j=0;j<n;j++)
{
if(m>a[j])
w=w+1;
}

for(j=0;j<w;j++)
{
printf("%d",a[j]);
printf(" ");
}
printf("%d",m);
for(j=w;j<n;j++)
{
printf(" ");
printf("%d",a[j]);
}
}
printf("\n");
scanf("%d%d",&n,&m);
}
}

2020
Problem Description
n(n<=100)

Input
n, n n=0

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

#include<stdio.h>
main()
{
int n,m,a[100],b[100],c,d,e,f,i,j,k;
while(scanf("%d",&n)!=EOF&&n!=0)
{
for(i=0;i<n;i++)
scanf("%d",&a[i]);
f=0;
for(j=0;j<n;j++)
{
c=0;
for(i=0;i<n;i++)
{
if(a[i]<0)
m=-a[i];
else m=a[i];
if(c<=m)
{
c=m;
b[j]=a[i];
k=i;
}
}
a[k]=0;
if(f)
printf(" ");

printf("%d",b[j]);
f=f+1;
}
printf("\n");
}
}

2021
Problem Description
8

Input
nn<100
n
n=0

Output
x,

Sample Input
3
1 2 3
0

Sample Output
4

Author
lcy

Source
C

Recommend
lcy

#include<stdio.h>
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

N N
6 AH,AM,AS,BH,BM,BS A B

Output
A+B 3
0~59

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

#include<stdio.h>
main()
{int i,j,a,b,c,d,e,f,n,s;
while(scanf("%d",&n)!=EOF)
{
c=0;d=0;e=0;
for(i=0;i<n;i++)
{
a=0;b=0;c=0;d=0;e=0;f=0;
scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
a=a+d;
b=b+e;c=c+f;
j=0;

while(c>60)
{
c=c-60;
j=j+1;
}
b=b+j;
s=0;
while(b>60)
{
b=b-60;
s=s+1;
}
a=a+s;
printf("%d %d %d\n",a,b,c);
}
}
}

2039
Problem Description

Input
M M A,B,C
A,B,C <1000;

Output
A,B,C YES NO

Sample Input
2
1 2 3
2 2 2

Sample Output
NO
YES

Author
linle

Source
2005

Recommend
lcy

#include<stdio.h>
main()
{
double n,a,b,c,i;
while(scanf("%lf",&n)!=EOF)
{
for(i=0;i<n;i++)
{
scanf("%lf%lf%lf",&a,&b,&c);
if((a+b)>c&&(b+c)>a&&(a+c)>b)
printf("YES\n");
else
printf("NO\n");
}
}
}

2040
Problem Description
220 ()

284 12471 142 220

Input
M M , A,B 0 <= A,B
<= 600000 ;

Output
A B YES NO

Sample Input
2
220 284
100 200

Sample Output
YES
NO

Author
linle

Source
2005

Recommend
lcy

#include<stdio.h>
main()
{
double n,a,b,c,i;

while(scanf("%lf",&n)!=EOF)
{
for(i=0;i<n;i++)
{
scanf("%lf%lf%lf",&a,&b,&c);
if((a+b)>c&&(b+c)>a&&(a+c)>b)
printf("YES\n");
else
printf("NO\n");
}
}
}

S-ar putea să vă placă și