算法标准答案

Problem H: 乘法口诀
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 11234 Solved: 3034

Description

Input

Output

Sample Input
1 2 6

Sample Output
1*1=1

1*1=1 1*2=2 2*2=4

1*1=1 1*2=2 1*3=3 2*2=4 2*3=6 3*3=9

1*4=4 1*5=5 1*6=6

2*4=8

3*4=12 4*4=16

2*5=10 3*5=15 4*5=20 5*5=25 2*6=12 3*6=18 4*6=24 5*6=30 6*6=36

HINT
%-2d 表示对齐方式为左对齐 例如，printf("%-6d",100);将输出：
#include<stdio.h> #include<string.h> int main() { int n,i,j; char a[10][10]; while(scanf("%d",&n)!=EOF) { for(i=1;i<=n;i++) { for(j=1;j<=i-1;j++) { a[i][j]=j*i; printf("%d*%d=%-2d ",j,i,a[i][j]); } printf("%d*%d=%-2d",i,i,i*i); printf("\n"); } printf("\n"); } return 0; }

100

Problem G: 打印金字塔
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 6241 Solved: 3777

Description

Input

Output

Sample Input
1 3

Sample Output
* * *** *****

HINT

}//外循环
#include<stdio.h> int main() { int n,i,j,k; while(scanf("%d",&n)!=EOF) { for(i=1;i<=n;i++) { for(j=1;j<=n-i;j++) printf(" "); for(k=1;k<2*i;k++) printf("*"); printf("\n") ; } } return 0; }

3920: 老外买瓷砖
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1344 Solved: 656

Description

Input

Output

Sample Input
2 Hello. How are you!

Sample Output
a:1 e:1 i:0 o:1 u:0 a:2 e:1 i:1 o:2 u:1

HINT

#include <stdio.h> void f(int* a,char* s) { { switch(*s) { case 'h': case 'H': case 'A': case 'a':a[0]++; break; case 'E': case 'e': a[1]++;break; case 'Y': while(*s)

case 'y': case 'I': case 'i': a[2]++; break; case 'O': case 'o': a[3]++; break; case 'U': case 'u': a[4]++;break; } s++; }} int main() { char s[200]; int a[5]; int n,i,j; scanf("%d",&n); getchar(); for(i=0;i<n;i++) { for(j=0;j<5;j++) a[j]=0; gets(s); f(a,s); printf("a:%d\ne:%d\ni:%d\no:%d\nu:%d\n",a[0],a[1],a[2],a[3],a[4]); } return 0;}

Problem A: 双层金字塔
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 4962 Solved: 3290

Description

Input

Output

Sample Input
2 5

Sample Output
* *** * * *** ***** ******* ********* ******* ***** *** *
#include<stdio.h> int main() {int n,i,j,a,b; while(scanf("%d",&n)!=EOF) { for(i=1;i<=n;i++) { for(j=1;j<=n-i;j++) printf(" "); for(j=1;j<=2*i-1;j++) printf("*");

printf("\n"); } for(a=1;a<n;a++) { for(b=1;b<=a;b++) printf(" "); for(b=1;b<=2*(n-a)-1;b++) printf("*"); printf("\n"); }} return 0; }

3919: 堆瓷砖
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1819 Solved: 750

Description

Input

Output

Sample Input
2 4 3 4 5 6

3 8 4 9

Sample Output
6 5 4 3 9 8 4

HINT
n m 不会超过 50
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

#include <stdio.h> int main() { int n,i,j,l,a[50],index,t,k; scanf("%d",&n); for(k=0;k<n;k++) { scanf("%d",&l); for(j=0;j<l;j++) scanf("%d",&a[j]); for(j=0;j<l;j++) { index=j; for(i=j+1;i<l;i++) if(a[index]<a[i]) index=i; {t=a[index]; a[index]=a[j]; a[j]=t; } } for(j=0;j<l-1;j++) printf("%d ",a[j]); printf("%d\n",a[l-1]); } return 0; }

32 33 34

3918: 定制瓷砖
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1746 Solved: 1092

Description

Input

Output

Sample Input
2 6 12 6 8

Sample Output
6 2
#include<stdio.h>

int main() { int n,i,a,b,t,j,m; scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d%d",&a,&b); if(a>b) {t=a;a=b;b=t;} for(j=a;j>=2;j--) { if(a%j==0&&b%j==0) break; m=j; } printf("%d\n",j); } return 0; }

4135: 新年挂灯笼
Time Limit: 1 Sec Memory Limit: 128 MB Submit: 1025 Solved: 525

Description

Input

Output

Sample Input
3 1

2 3

Sample Output
* ** **** ** *** ***** ******* ***** ***
#include <stdio.h> int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i++) { int x; int j; scanf("%d",&x); for(j=1;j<=x;j++) { for(int k=1;k<=x-j;k++) printf(" "); for(int k=0;k<(x+2*(j-1));k++) printf("*"); printf("\n"); } for(int j=x;j>1;j--) { for(int k=1;k<x-j+2;k++) printf(" "); for(int k=0;k<(x+2*(j-2));k++) printf("*");

printf("\n"); } } return 0; }

4137: 压岁钱
Time Limit: 1 Sec Memory Limit: 128 MB Submit: 1186 Solved: 721

Description

Input

Output

Sample Input
2 3 100 200 300 4 100 400 50 600

Sample Output
600 1150
#include <stdio.h> int main()

{ int n,m,i,t,j,s; scanf("%d",&t); for(i=1;i<=t;i++) { scanf("%d",&n); s=0; for(j=0;j<n;j++) { scanf("%d",&m); s=s+m; } printf("%d\n",s); } return 0; }

2413: 求三角形面积——C 语言初学者百 题大战之十四
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 7507 Solved: 4152

Description

Input

Output

Sample Input
3 4 5

Sample Output
6.00

HINT

#include<stdio.h> #include<math.h> int main() { float a,b,c,s,p; scanf("%f %f %f",&a,&b,&c); p=(a+b+c)*0.5; s=sqrt(p*(p-a)*(p-b)*(p-c)); printf("%.2f\n",s); return 0; }

2412: 鹦鹉学舌 3——C 语言初学者百题大 战之十三
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 5169 Solved: 2593

Description

Input

Output

Sample Input
I am a student.

Sample Output
I am a student.
#include<stdio.h> #include<string.h> int main() { char a[81], * p=a; gets(a); puts(a); }

2411: 鹦鹉学舌 2——C 语言初学者百题大 战之十二
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 4234 Solved: 3456

Description

Input

Output

Sample Input
e

Sample Output
e
#include<stdio.h> int main() { char c; c = getchar(); putchar(c); printf("\n"); return 0; }

3549: 更改大小写
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 4089 Solved: 2942

Description

Input

Output

Sample Input
There are 3 pens.

Sample Output
THERE ARE 3 PENS.

HINT
#include<stdio.h> #include<string.h> int main() { char s[80]; int len,i; gets(s); len=strlen(s); for(i=0;i<len;i++) { if(s[i]>='a'&&s[i]<='z') s[i]=s[i]-32; } puts(s); return 0; } //输出修改后的字符串 //将小写字母转换为大写 //输入一段字符 //计算字符串长度

3545: 颠倒字符串
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 4532 Solved: 2539

Description

Input

Output

Sample Input
ABC XYZ My god

Sample Output
ZYX CBA dog yM
#include <stdio.h> int main() { char c[90]; int n,i,a; while((c[0]=getchar())!=EOF) { i=1; while((c[i]=getchar())!='\n') i++; for(n=i-1;n>=0;n--) printf("%c",c[n]); putchar('\n'); } return 0; }

Problem A: 零起点学算法 87——打印所 有低于平均分的分数
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 4813 Solved: 1344

Description

Input

Output

Sample Input
3 40 50 60 2 90 80 5 10 10 90 80

Sample Output
40 80 10 10
#include <stdio.h> int main() { int a,p[100],flag=0; while(scanf("%d",&a)!=EOF) { int i,sum; double ave; sum=0; for(i=0;i<a;i++) { scanf("%d",&p[i]); sum=sum+p[i]; } ave=(float)sum/a; for(i=0;i<a;i++) { if(p[i]<ave) {

if(flag==0) { printf("%d",p[i]); flag=1; } else { printf(" %d",p[i]); } } } printf("\n"); flag=0; }}

2445: 平方和与立方和
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 4252 Solved: 2145

Description

Input

Output

Sample Input
3 1 2 5

Sample Output

4 28 20 152
#include<stdio.h> int main() { int a,b,t,i,s,c; while(scanf("%d%d",&a,&b)!=EOF) { s=0; c=0; if(a>b) { t=a; a=b; b=t;}

for(i=a;i<=b;i++) { if(i%2==0) if(i%2==1) } printf("%d %d\n",s,c); } return 0; } s=s+i*i; c=c+i*i*i;

2444: 求奇数的乘积
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 4692 Solved: 3042

Description

Input

Output

Sample Input
3 1 2 3 4 2 3 4 5

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

Problem A: 偶数排序
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1959 Solved: 987

Description

Input

Output

Sample Input
10 8 4 14 2 11 30 40 500 17 100 8 80 200 99 -12 34 55 88 11

Sample Output
500 100 40 30 14 8 4 2 200 88 80 34 -12

#include<stdio.h> int main() { int i,j,t,n; int a[101],b[101]; while(scanf("%d",&n)!=EOF){ for(i=1;i<=n;i++){ scanf("%d",&a[i]); } for(i=1;i<=n;i++){ for(j=i;j<=n;j++){ if(a[i]<a[j]){ t=a[i]; a[i]=a[j]; a[j]=t; } else continue; }}

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

Problem B: 零起点学算法 92——元素前 移1位
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1934 Solved: 1231

Description

Input

Output

Sample Input
4 1 2 3 4

Sample Output
2 3 4 1

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

Problem C: 零起点学算法 86——Fibonacc
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1798 Solved: 983

Description
Fibonacci 数列定义为（1,1,2,3,5,8,.....），即每个元素是前两个元素的 和。如果一个 Fibonacci 数与所有小于它的 Fibonacci 数互质，那么称之为 Fibonacci 质数。现在要求你输出前 n 个 Fibonacci 数 The Fibonacci Numbers {0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 ...} are defined by the recurrence: F(0)=0 F(1)=1 F(i)=F(i-1)+F(i-2) Write a program to calculate the Fibonacci Numbers.

Input

The first line of the input file contains a single integer T, the number of test cases. The following T lines,each contains an integer n ( 0 <= n <= 45 ), and you are expected to calculate Fn.

Output
Output Fn on a separate line.

Sample Input
5 0 3 5 9 20

Sample Output
0 2 5 34 6765
#include<stdio.h> int f(int n); main() { int t,i; int n,c[50]; scanf("%d",&t); for(i=0;i<t;i++) scanf("%d",&c[i]); for(i=0;i<t;i++){ n=c[i]; f(n); }}

int f(int n) { int i,f1=1,f2=1,f3; if(n==0) printf("0\n"); else if(n==1||n==2) { printf("1\n"); } else { for(i=0;i<n-2;i++) { f3=f1+f2; f2=f1; f1=f3; } printf("%d\n",f1); } }

3542: 插入一个数到数列中
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 3257 Solved: 1671

Description

Input

Output

Sample Input

35 -5 90

Sample Output
0 10 20 30 35 40 50 60 70 80 -5 0 10 20 30 40 50 60 70 80 0 10 20 30 40 50 60 70 80 90
#include<stdio.h> int main() { int n,m,i,l,j,k; int a[20],b[20]; while(scanf("%d",&m)!=EOF){ for(i=0;i<9;i++){ a[i]=10*i; } for(i=0;i<10;i++){ if(m<a[i]) break; } if(i!=10){ for(j=9;j>i;j--) a[j]=a[j-1]; a[i]=m; } else a[9]=m; for(i=0;i<10;i++){ if(i!=9) printf("%d ",a[i]); else printf("%d\n",a[i]); } } }

3539: N 个数从小到大排序
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 5854 Solved: 2635

Description

Input

Output

Sample Input
10 -4 5 12 88 23 -9 2 0 8 10 5 12 3 4 9 -2

Sample Output
-9 -4 0 2 5 8 10 12 23 88 -2 3 4 9 12
#include<stdio.h> int main() { int i,j,t,n; int a[101],b[101]; while(scanf("%d",&n)!=EOF){ for(i=1;i<=n;i++){ scanf("%d",&a[i]); } for(i=1;i<=n;i++){

for(j=i;j<=n;j++){ if(a[i]>a[j]){ t=a[i]; a[i]=a[j]; a[j]=t; } else continue; }} for(i=1;i<=n;i++){ if(i!=n) printf("%d ",a[i]); else printf("%d\n",a[i]); } } }

3537: 最大数与数列最后一个数交换
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 4345 Solved: 1875

Description

Input

Output

Sample Input

5 3 5 2 8 1 9 88 33 55 99 44 66 77 22 11

Sample Output
3 5 2 1 8 88 33 55 11 44 66 77 22 99
#include<stdio.h> int main() { int i,j,max,n; int a[100]; while(scanf("%d",&n)!=EOF) { for(i=0;i<n;i++) scanf("%d",&a[i]); max=a[0]; j=0; for(i=1;i<n;i++) { if(a[i]>max) { max=a[i]; j=i; } } a[j]=a[n-1]; a[n-1]=max; for(i=0;i<n-1;i++) printf("%d ",a[i]); printf("%d\n",a[n-1]); } return 0; }

3886: 零起点学算法 85——数组中插入一 个数
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 3497 Solved: 1250

Description

Input

Output

Sample Input
3 1 2 5 3 1

Sample Output
1 2 3 5 2
#include<stdio.h> int main() { int n,m,i,l,j,k; int a[21],b[21]; while(scanf("%d",&n)!=EOF){ for(i=0;i<n;i++){ scanf("%d",&a[i]);

} scanf("%d%d",&m,&k); for(i=0;i<n;i++){ if(m<a[i]) break; } if(i!=n){ for(j=n;j>i;j--) a[j]=a[j-1]; a[i]=m; } else a[i]=m; for(i=0;i<=n;i++){ if(i!=n) printf("%d ",a[i]); else printf("%d\n",a[i]); } printf("%d\n",a[k]); } }

3885: 零起点学算法 84——数组中删数 II
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 4532 Solved: 1678

Description

Input

Output

Sample Input
5 1 2 3 4 3 3

Sample Output
1 2 4
#include<stdio.h> int main() { int n,m,i,l,j,k; int a[21],b[21]; while(scanf("%d",&n)!=EOF){ for(i=0;i<n;i++){ scanf("%d",&a[i]); } scanf("%d",&m); for(i=0;i<n;i++){ if(m==a[i]) { if(i!=n-1) continue; else printf("\n"); } else { if(i!=n-1) printf("%d ",a[i]); else printf("%d\n",a[i]); } } } }

Problem A: 零起点学算法 83——数组中 删数
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 7443 Solved: 2254

Description

Input

Output

Sample Input
4 1 2 3 4 3

Sample Output
1 2 4

HINT
m 有可能在原数组中找不到，找不到则输出原数组
#include <stdio.h> int main(){ int n,a[20],i,m; while(scanf("%d",&n)!=EOF) {

for(i=0;i<n;i++) scanf("%d",&a[i]); scanf("%d",&m); for(i=0;i<n;i++) if(a[i]==m){ int j; for(j=i;j<n-1;j++) a[j]=a[j+1]; break; } int t=n-1; if(i!=n)t--; for(i=0;i<t;i++) printf("%d ",a[i]); printf("%d\n",a[i]); } return 0; }

Problem A: 零起点学算法 82——数组中 查找数
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 7125 Solved: 3536

Description

Input

Output

Sample Input

3 4 5 6 5 4 2 2 2 2 2

Sample Output
1 0
#include<stdio.h> int main() { int n,a[20]; int i,j,m; while (scanf("%d", &n) != EOF) { for(i=0; i<n; i++) { scanf("%d",&a[i]); } scanf("%d",&m); for(j=0; j<n; j++) { if(a[j]==m) { printf("%d\n",j); break; } } if(j == n) printf("No\n"); } return 0; }

Problem A: 零起点学算法 81——找出数 组中最大元素的位置（下标值）
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 8840 Solved: 3524

Description

Input

Output

Sample Input
4 1 4 5 6

Sample Output
6 3
#include<stdio.h> int main() { int n,a[10],i,j,max; while(scanf("%d",&n)!=EOF) { max=0;j=0; for(i=0;i<n;i++) { scanf("%d",&a[i]); if(max<a[i]){max=a[i];j=i;} } printf("%d %d\n",max,j); }

return 0; }

Problem A: 零起点学算法 80——逆序输 出（数组练习）
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 8884 Solved: 3256

Description

Input

Output

Sample Input
2 3 1 2 3 5

2 3 1 4 5

Sample Output
3 2 1 5 4 1 3 2
#include<stdio.h> int main() { int T,j,n,i; scanf("%d",&T); for(j=1;j<=T;j++) { scanf("%d",&n); int a[1000]; for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=n-1;i>=1;i--) { printf("%d ",a[i]); } printf("%d\n",a[0]); } return 0; }

3510: 完数
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 3850 Solved: 2047

Description

Input

Output

Sample Input
6 28 42

Sample Output
6 is cloze. 28 is cloze. 42 is not cloze.

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

2429: 绝配队伍
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 7291 Solved: 3876

Description

Input

Output

Sample Input
153 610

Sample Output
Yes No

#include<stdio.h> int main() { int n,a,b,c; while(scanf("%d",&n)!=EOF) { a=n/100; b=n/10%10; c=n%10; if(a*a*a+b*b*b+c*c*c==n) printf("Yes\n"); else printf("No\n"); } return 0; }

3519: 输入任意 N 个数，求和
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1919 Solved: 1206

Description

Input

Output
n 个数的和。

Sample Input
6 11 19 2 7 8 31 4 11 23 8 1

Sample Output
s=78

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

Problem A: 计算数列和
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 3558 Solved: 2038

Description

Input

Output

Sample Input
10 15

20

Sample Output
s=16.48 s=24.57 s=32.66
#include<stdio.h> int main() { int n; while(scanf("%d",&n)!=EOF) { int a[1000]; int i; double t=2; a[0]=1; a[1]=2; for(i=2;i<=n;i++) { a[i]=a[i-1]+a[i-2]; } for(i=1;i<n;i++) { t+=1.0/a[i]*a[i+1]; } printf("s=%.2lf\n",t); } return 0; }

Problem A: 指针：调用自定义交换函数， 完成三个数整从小到大排列
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 4493 Solved: 2942

Description

Input

Output

Sample Input
9 2 7 0 -2 12 8 3 1

Sample Output
2 7 9 -2 0 12 1 3 8

#include<stdio.h> void swap(int*p1, int*p2) { int p; p=*p1; *p1=*p2; *p2=p; } int main(void) { int a,b,c; while(scanf("%d%d%d",&a,&b,&c)!=EOF) { if(a>b) swap (&a,&b); if(a>c) swap (&a,&c); if(b>c) swap (&b,&c); printf("%d %d %d\n",a,b,c); } return 0;

}

Problem B: 指针：调用自定义交换函数， 完成 5 个浮点数从小到大排列
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 3704 Solved: 2071

Description

Input

Output

Sample Input
5.5 4.4 3.3 2.2 1.1 3.1 2 0 7.2 5.4 7.2 -3.4 0 -2 1.2

Sample Output
1.1 2.2 3.3 4.4 5.5 0.0 2.0 3.1 5.4 7.2 -3.4 -2.0 0.0 1.2 7.2

#include<stdio.h> void swap(float*p1, float*p2) { float p; p=*p1;

*p1=*p2; *p2=p; } int main(void) { float a,b,c,d,e; while(scanf("%f%f%f%f%f",&a,&b,&c,&d,&e)!=EOF) { if(a>b) swap (&a,&b); if(a>c) swap (&a,&c); if(a>d) swap (&a,&d); if(a>e) swap (&a,&e); if(b>c) swap (&b,&c); if(b>d) swap (&b,&d); if(b>e) swap (&b,&e); if(c>d) swap (&c,&d); if(c>e) swap (&c,&e); if(d>e) swap (&d,&e); printf("%.1f %.1f %.1f %.1f %.1f\n",a,b,c,d,e); } return 0; }

Problem C: 指针：有 n 个整数，使其前面 各数顺序向后移 m 个位置， 最后 m 个数变 成最前面 m 个数
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 2344 Solved: 1448

Description

Input

Output

Sample Input
10 4 1 2 3 4 5 6 7 8 9 10 7 2 1 2 3 4 5 6 7

Sample Output
7 8 9 10 1 2 3 4 5 6 6 7 1 2 3 4 5

#include<stdio.h> void move(int *a, int n, int m) { int b[20],i; for(i=0;i<m;i++) {b[i]=a[n-m+i];} for(i=n-1;i>=m;i--) {a[i]=a[i-m];} for(i=0;i<m;i++) {a[i]=b[i];} } int main() { int i,n,m,a[20]; while(scanf("%d%d",&n,&m)==2) { for(i=0;i<n;i++) {scanf("%d",a+i);} move(a,n,m); for(i=0;i<n;i++) {printf("%d%c",a[i],i==n-1?'\n':' '); } } }

Problem D: 指针：调用自定义排序函数 sort，对输入的 n 个数进行从小到大输出。
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 3437 Solved: 1931

Description

Input

Output

Sample Input
5 9 4 3 2 1 6 34 23 12 78 -20 0

Sample Output
1 2 3 4 9 -20 0 12 23 34 78

Problem E: 指针：自定义函数 sumDiff()， 调用它来求两个数的和、差
Time Limit: 1 Sec Memory Limit: 64 MB

Submit: 4459 Solved: 3120

Description

Input

Output

Sample Input
3 5 9 8

Sample Output
sum=8 diff=-2 sum=17 diff=1

Problem F: 自定义函数 strcomp()， 实现两 个字符串的比较
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 2103 Solved: 1417

Description

1、0 或-1，分别表示 s1>s2,s1=s2,s1<>

Input

Output

Sample Input
china chinese world hello sea sea

Sample Output
-1 1 0

Problem G: 结构体：计算输入日期是该年 的第几天
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 5719 Solved: 3139

Description

Input

Output

Sample Input
2006-10-1

Sample Output
274

Description

Input

Output

Sample Input
101 Xue 87 90

102 Lin 98 92 103 Liu 89 83

Sample Output
ave[0]=88.5 ave[1]=95.0 ave[2]=86.0

#include<stdio.h> struct student {

int num; char name[20]; int score1; int score2;

}stu[3]; void main() { int t1,t2,t3; struct student *p; for(p=stu;p<stu+3;p++) {scanf("%d\n%c\n%d\n%d\n"); t1=(stu[0].score1+stu[0].score2)/2.0; t2=(stu[1].score1+stu[1].score2)/2.0; t3=(stu[2].score1+stu[2].score2)/2.0; } printf("ave[1]=%.1f\n",t1); printf("ave[2]=%.1f\n",t2); printf("ave[3]=%.1f\n",t3); }

Problem I: 结构体：求最高分和最低分
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 3220 Solved: 2220

Description

Input

Output

Sample Input
4 1001 Li 76 1002 Zhang 92 1003 Liu 85 1004 Wang 70

Sample Output

1002 Zhang 92 1004 Wang 70

Problem J: 结构体：按成绩排序
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 3753 Solved: 2441

Description

Input

Output

Sample Input
4 1001 Li 76 1002 Zhang 92 1003 Liu 85

1004 Wang 70

Sample Output
1004 Wang 70 1001 Li 76 1003 Liu 85 1002 Zhang 92

Problem A: 深入浅出学算法 001-求最大 公约数
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1824 Solved: 1066

Description

Input

Output

Sample Input
2

18 12 6 5

Sample Output
6 1

HINT
c 语言基础不够扎实的赶快到第 29 页去饿补吧 多组测试数据输入输出不清楚的赶快去做 3838 到 3843 的题目，以后不说就是多 组
#include<stdio.h> int main() { int a,b,n,t,j,m; scanf("%d",&n); while(scanf("%d%d",&a,&b)!=EOF) { for(j=a;j>=1;j--) { if(a%j==0&&b%j==0) break; } printf("%d\n",j); } return 0; }

Problem B: 深入浅出学算法 002-n 个 1
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1834 Solved: 588

Description

Input

Output

Sample Input
1 11

Sample Output
2

#include <stdio.h> int main() { int c, n, m, r, p; scanf("%d", &c); while(c--) { scanf("%d", &m); if(!(m&1) || (m%10==5)) { printf("-1\n"); continue; } p = 1; r = 1; n = 1; while(r%m != 0) { p = p*10%m; r = (r+p)%m; n++; }

printf("%d\n", n); } return 0; }

Problem C: 深入浅出学算法 003-计算复 杂度
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 784 Solved: 305

Description

Input

Output

Sample Input
2 1 2

Sample Output
1 n

#include <stdio.h> int main() { int i,T,a; scanf("%d",&T); for(i=1;i<=T;i++) { scanf("%d",&a); if(a==1) printf("1\n"); else if(a==2) printf("n\n"); else if(a==3) printf("2^n\n"); else if(a==4) printf("n^2\n"); else if(a==5) printf("nlogn\n"); else if(a==6) printf("n^2\n"); else if(a==7) printf("n^3\n"); }

return 0; }

Problem D: 深入浅出学算法 004-求多个 数的最小公倍数
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1257 Solved: 329

Description

Input

Output

Sample Input
1 3 12 18 6

Sample Output
36

Problem E: 深入浅出学算法 005-数 7
Time Limit: 1 Sec Memory Limit: 64 MB

Submit: 3698 Solved: 954

Description

Input

Output

Sample Input
1 3

Sample Output
7 14 17 21 27 28...

#include<stdio.h> int main() { int T,k,i,j; scanf("%d",&T); for(i=1;i<=T;i++) { scanf("%d",&k); for(j=k;j<=97;j++) if(j%7==0||j%10==7||j/10==7) printf("%d ",j); printf("98\n"); } return 0;

}

Problem F: 深入浅出学算法 006-求不定方 程的所有解
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 2018 Solved: 871

Description

Input

Output

Sample Input
1 1 2 3

Sample Output
1 1

Problem G: 深入浅出学算法 007-统计求 和

Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1858 Solved: 821

Description

Input

Output

Sample Input
1 3

Sample Output

Problem B: 均分纸牌
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1662 Solved: 804

Description

Input

Output

Sample Input
4 9 8 17 6 0

Sample Output
3

HINT
#include<stdio.h> int main() { int i, n,ave,a; int s[105]; while(scanf("%d",&n)!=EOF&&n!=0) { ave=0; for(i=0;i<n;i++) { scanf("%d",&s[i]); ave+=s[i]; } ave/=n; a=0; for(i=0;i<n;i++) { s[i]-=ave; if(s[i]!=0)

{ a++; s[i+1]+=s[i]; }} printf("%d\n",a); } return 0; }

Problem C: 连数问题
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1541 Solved: 744

Description

Input
N N 个数

Output

Sample Input
3 13 312 343 0

Sample Output
34331213

#include <stdio.h>

int CompareInt(int a,int b) { int a1=a,b1=b,la=10,lb=10; while(a/la) { la*=10; } while(b/lb) { lb*=10; } return (a*lb+b)-(b*la+a); } int main() { int i,j,n; int data[20],temp; while(1) { scanf("%d",&n); if(n<=0||n>20) break; for(i=0;i<n;i++) { scanf("%d",&data[i]); } for(j=0;j<n-1;j++) for(i=0;i<n-1-j;i++) { if(CompareInt(data[i],data[i+1])<0) { temp=data[i+1]; data[i+1]=data[i]; data[i]=temp; } } for(i=0;i<n;i++) { printf("%d",data[i]); } printf("\n"); } return 0;}

Problem A: Delete Number
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 2561 Solved: 781

Description
Given 2 integer number n and m. You can delete m digits from the number n, then number n changes to a new number n1. Tell me how to delete the number, you can get the smallest one. For example,
m: 1 n: 1456

n1 may be 145, 156, 146, 456 the smallest one is 145. Then n1 should be 145.

Input
The input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case consists of one single line containing two integer number m(1 <= m <= 1000), and n(1 <= n < 101000).

Output
Your program must output a single line for each test case. The line should contain the number n1.

Sample Input
1 1 1456

Sample Output
145

#include <stdio.h> #include <string.h> void del (char *p)

{ while (*p!='\0') { *p=*(p+1); p++; } } int main() { int T;char c; scanf ("%d",&T); while (T--) { char str[1000]; int n; char *p; scanf ("%d",&n); scanf ("%s",str); p=str+1; while (*p!='\0') { if (*(p-1)>*p&&n>0) { del (p-1); n--; p=str+1; continue; } p++; } while (n) { p--; del(p); n--; } while (str[0]=='0') { strcpy(str,str+1); } if(str[0]=='\0')printf("0"); printf ("%s\n",str); } return 0;

}

Problem E: Packets
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 357 Solved: 166

Description
A factory produces products packed in square packets of the same height h and of the sizes 1*1, 2*2, 3*3, 4*4, 5*5, 6*6. These products are always delivered to customers in the square parcels of the same height h as the products have and of the size 6*6. Because of the expenses it is the interest of the factory as well as of the customer to minimize the number of parcels necessary to deliver the ordered products from the factory to the customer. A good program solving the problem of finding the minimal number of parcels necessary to deliver the given products according to an order would save a lot of money. You are asked to make such a program.

Input
The input file consists of several lines specifying orders. Each line specifies one order. Orders are described by six integers separated by one space representing successively the number of packets of individual size from the smallest size 1*1 to the biggest size 6*6. The end of the input file is indicated by the line containing six zeros.

Output
The output file contains one line for each line in the input file. This line contains the minimal number of parcels into which the order from the corresponding line of the input file can be packed. There is no line in the output file corresponding to the last null'' line of the input file.

Sample Input
0 0 4 0 0 1 7 5 1 0 0 0

0 0 0 0 0 0

Sample Output
2 1

HINT

#include<iostream> #include<cstdio> using namespace std; int main() { int p[4]={0,5,3,1},a[10]; while(1) { int sum=0; for(int i=1;i<=6;i++) { scanf("%d",&a[i]); sum+=a[i]; } if(sum==0) break; sum=0; sum=a[4]+a[5]+a[6]+a[3]/4; if(a[3]%4!=0) sum++; int need2=a[4]*5+p[a[3]%4]; if(need2<a[2]) { sum+=(a[2]-need2)/9; if((a[2]-need2)%9!=0) sum++; } int need1=sum*36-a[2]*4-a[3]*9-a[4]*16-a[5]*25-a[6]*36; if(need1<a[1]) { sum+=(a[1]-need1)/36;

if((a[1]-need1)%36!=0) sum++; } printf("%d\n",sum); } return 0; }

Problem F: Box of Bricks
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 598 Solved: 268

Description
Little Bob likes playing with his box of bricks. He puts the bricks one upon another and builds stacks of different height. "Look, I've built a wall!", he tells his older sister Alice. "Nah, you should make all stacks the same height. Then you would have a real wall.", she retorts. After a little con- sideration, Bob sees that she is right. So he sets out to rearrange the bricks, one by one, such that all stacks are the same height afterwards. But since Bob is lazy he wants to do this with the minimum number of bricks moved. Can you help?

Input
The input consists of several data sets. Each set begins with a line containing the number n of stacks Bob has built. The next line contains n numbers, the heights hi of the n stacks. You may assume 1 <= n <= 50 and 1 <= hi <= 100. The total number of bricks will be divisible by the number of stacks. Thus, it is always possible to rearrange the bricks such that all stacks have the same height. The input is terminated by a set starting with n = 0. This set should not be processed.

Output
For each set, first print the number of the set, as shown in the sample output. Then print the line "The minimum number of moves is k.", where k is the minimum number of bricks that have to be moved in order to make all the stacks the same height. Output a blank line after each set.

Sample Input
6 5 2 4 1 7 5 0

Sample Output
Set #1 The minimum number of moves is 5.

#include <stdio.h> #include <algorithm> using namespace std; int main() { int n,cas = 1; while(~scanf("%d",&n),n) { int a[100],i,sub = 0; for(i = 0;i<n;i++) { scanf("%d",&a[i]); sub+=a[i]; } sub = sub/n; sort(a,a+n); int sum = 0; printf("Set #%d\nThe minimum number of moves is ",cas++); while(a[n-1]>sub) {

if(a[n-1]-sub>sub - a[0]) { sum+=sub-a[0]; a[n-1] = a[n-1] - (sub-a[0]); } else if(a[n-1]-sub == sub - a[0]) { sum+=a[n-1]-sub; a[n-1] = sub; a[0] = sub; } else { sum += a[n-1] - sub; a[n-1] = sub; a[0] = a[0] + a[n-1] - sub; } sort(a,a+n); } printf("%d.\n\n",sum); } return 0; }

Time Limit:1000MS Memory Limit:65536K Total Submit:488 Accepted:197

Description

Input

Output

Sample Input
10 3 18 7 14 10 12 23 41 16 24

Sample Output
6 简单动态规划题，给予我们一种思想！！ 代码如下：
#include<stdio.h> int Longest_Increasing(int num[],int List[],int n)//List[i]为包含 i 项在内的最长不下降子序列 { int i,j; for(i=1;i<n;i++) { for(j=0;j<i;j++)

{ if(num[i]>num[j]&&List[i]<List[j]+1) List[i]=List[j]+1; } } return 0; } int main() { int n,i,ans; int num[1001],List[1001]; while(scanf("%d",&n)!=EOF) { for(i=0;i<n;i++) { List[i]=1; scanf("%d",&num[i]); } Longest_Increasing(num,List,n); printf("最优解：\n"); for(i=0;i<n;i++) printf("%d ",List[i]); printf("\n");*/ ans=0; for(i=0;i<n;i++) if(List[i]>ans) ans=List[i]; printf("%d\n",ans); } return 0; }

/**//*

=yj； （不知道怎么输出大括号，悲剧啊！）

for(i=1;i<=m;i++) for(j=1;j<=n;j++) { if(x[i]==y[j]) { c[i][j]=c[i-1][j-1]+1; b[i][j]=1; } else { if(c[i-1][j]>=c[i][j-1]) { c[i][j]=c[i-1][j]; b[i][j]=2;

//二重循环

} else { c[i][j]=c[i][j-1]; b[i][j]=3; } } } }

void LCS(int i,int j,char x[],int b[][100]) //递归求得最长子序列 { if(i==0||b==0) return; if(b[i][j]==1) { LCS(i-1,j-1,x,b); printf("%c",x[i]); } else if(b[i][j]==2) LCS(i-1,j,x,b); else LCS(i,j-1,x,b); }

int main() { char x[100],y[100];

int i,j; int c[100][100],b[100][100]; scanf("%s %s",x+1,y+1); c[0][0]=0; LCSLength(7,6,x,y,c,b); for(i=0;i<8;i++) { for(j=0;j<7;j++) { printf("%d ",c[i][j]); } printf("\n"); } LCS(7,6,x,b); printf("\n"); return 0; }

Time Limit:1000MS Memory Limit:65536K Total Submit:565 Accepted:328

Description

Input

Output

Sample Input
5 7 3 8 2 4

8 1 0 7 4 4 5 2 6 5

Sample Output
30

int main(){ while(scanf("%d",&n)!=EOF&&n!=0){ data_set(); solve(); } return 0; }

Time Limit:1000MS Memory Limit:65536K Total Submit:412 Accepted:237

Description

A +---2---+---3---+----1---+----2---+

| 2 |

| 1 |

| 2 |

| 2 |

| 3 |

+---2---+---3---+----4---+---5----+ | 3 | | | 4 | | 1 | | 2 | | 3

+---2---+---2---+---1----+---4----+ | 2 | | | 2 | | 1 | | 3 | | 4

+---1---+---3---+---2----+---3----+ B

Input

Output

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

1 4 1 2 2 2 1 3 4

2 5 4 3

Sample Output
13

Hint

#include<stdio.h> #include<string.h> const int maxn=110; const int inf=200000000; int n,m,a[maxn][maxn],r[maxn][maxn],d[maxn][maxn]; int min(int a,int b){ return a<b?a:b; } void data_set(){ for(int i=1;i<=n;i++) for(int j=1;j<m;j++) scanf("%d",&r[i][j]); for(int i=1;i<=m;i++) for(int j=1;j<n;j++) scanf("%d",&d[j][i]); for(int i=0;i<=n;i++) for(int j=0;j<=m;j++) a[i][j]=inf; } void solve(){ a[1][1]=0; for(int i=2;i<=m;i++)

a[1][i]=a[1][i-1]+r[1][i-1];

for(int i=2;i<=n;i++)

a[i][1]=a[i-1][1]+d[i-1][1];

for(int i=2;i<=n;i++){ for(int j=2;j<=m;j++){ a[i][j]=min(a[i][j-1]+r[i][j-1],a[i-1][j]+d[i-1][j]); } } printf("%d\n",a[n][m]); } int main() { while(scanf("%d%d",&n,&m)!=EOF){ data_set(); solve(); } }

Problem E: 深入浅出学算法 035-01 背包 问题
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 520 Solved: 295

Description

Input

Output

Sample Input
60 6 15 32 17 37 20 46 12 26 9 21 14 30

Sample Output
60 134

HINT

Problem D: 深入浅出学算法 034-最长公 共子序列
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 382 Solved: 219

Description

Input

Output

Sample Input
1 hsbafdreghsbacdba acdbegshbdrabsa

Sample Output

Problem A: 深入浅出学算法 027-皇后问 题
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1819 Solved: 805

Description

Input

Output

Sample Input
3 4

Sample Output
No 2 4 1 3

HINT

________________

|

|

| 1 |

|

|___|___|___|___|

| 2 |

|

|

|

|___|___|___|___|

|

|

|

| 3 |

|___|___|___|___|

|

| 4 |

|

|

|___|___|___|___|

#include <stdio.h> #include <math.h> #include <stdlib.h> int main() { int i,a[9],g,k,n,j; while(scanf("%d",&n)!=EOF) { i=1; a[i]=1; while(1) { g=1; for(k=i-1;k>=1;k--) { if(a[i]==a[k]||abs(a[i]-a[k])==i-k) { g=0; } } if(g&&i==n) { for(j=1;j<n;j++) { printf("%d ",a[j]); } printf("%d\n",a[j]); break; } if(i<n&&g) { i++; a[i]=1; continue; } while(a[i]==n&&i>1)

{ i--; } if(a[i]==n&&i==1) { printf("No\n"); break; } else { a[i]=a[i]+1; } } } return 0; }

Problem B: 深入浅出学算法 028-桥本分数 式
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1764 Solved: 826

Description

□ □ □

----- + ----- = -----□□ □□ □□

Input

Output

Sample Input

Sample Output
#include<stdio.h> int main() { int g,i,k,s,a[10]; long m1,m2,m3 ; i=1;a[1]=1;s=0; while(1) { g=1; for(k=i-1;k>=1;k--) if(a[i]==a[k]) { g=0; break; } if(i==9&&g==1&&a[1]<a[4]) { m1=a[2]*10+a[3]; m2=a[5]*10+a[6]; m3=a[8]*10+a[9]; if(a[1]*m2*m3+a[4]*m1*m3==a[7]*m1*m2) { s++; } } if(i<9&&g==1)

{ i++; a[i]=1;continue; } while(a[i]==9&&i>1) i--; if(a[i]==9&&i==1) break; else a[i]++; } printf("%d\n",s); return 0; }

Problem C: 深入浅出学算法 029-素数和 环
Time Limit: 10 Sec Memory Limit: 64 MB Submit: 1060 Solved: 541

Description

Input

Output

Sample Input
4

Sample Output
2

HINT
#include<stdio.h> #include<math.h> int main() { int t,i,j,n,k,s,a[2000],b[1000]; while(scanf("%d",&n)!=EOF) { for(k=1;k<=2*n;k++) b[k]=0; for(k=3;k<2*n;k+=2) { for(t=0,j=3;j<=sqrt(k);j+=2) if(k%j==0) { t=1; break; } if(t==0) b[k]=1; } a[1]=1; s=0; i=2; a[i]=2; while(1) { t=1; for(j=1;j<i;j++) if(a[j]==a[i]||b[a[i]+a[i-1]]!=1) {

t=0; break; } if(t&&i==n&&b[a[n]+1]==1) { s++; } if(t&&i<n) { i++; a[i]=2; continue; } while(a[i]==n&&i>1) i--; if(i>1) a[i]++; else break; } printf("%d\n",s); } }

Problem D: 深入浅出学算法 030-德布鲁 金环
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 118 Solved: 71

Description

Input

Output

Sample Input
2

Sample Output
1

HINT
#include <stdio.h> #include<math.h> int main() { int d,i,h,k,j,m,m1,m2,n,s,t,x,a[200]; while(scanf("%d",&n)!=EOF) { m=1; for(k=1;k<=n;k++) m=m*2; s=0; for(k=0;k<=n+m;k++) a[k]=0; a[n]=1; a[m-1]=1; i=n; while(1) { if(i==m-2) { for(h=0,j=n+1;j<=m-2;j++)

if(a[j]==0) h++; if(h==m/2-n) { for(t=0,k=0;k<=m-2;k++) for(j=k+1;j<=m-1;j++) { d=1; m1=0; m2=0; for(x=n-1;x>=0;x--) { m1=m1+a[k+x]*d; m2=m2+a[j+x]*d; d=d*2; } if(m1==m2) { t=1; break; } } if(t==0) { s++; } } } if(i<m-1) { i++; a[i]=0; continue; } while(a[i]==1&&i>n+1) i--; if(a[i]==1&&i==n+1) break; else a[i]=1; } printf("%d\n",s); } return 0; }

Problem E: 深入浅出学算法 031-装错信封
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 963 Solved: 586

Description

Input

Output

Sample Input
2

Sample Output
1

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

Problem F: 深入浅出学算法 032-装错信封
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 627 Solved: 425

Description

Input

Output

Sample Input
3

Sample Output
231 312

HINT
#include<stdio.h> int main() {

int n,i,k,g,q,j,a[11],s; while(scanf("%d",&n)!=EOF) { i=1;a[i]=2;s=0; while(1) { g=1; for(k=i;k>=1;k--) { if(a[k]==k) { g=0; break; } } for(j=1;j<=i;j++) { for(q=j+1;q<=i;q++) { if(a[j]==a[q]) { g=0; break; } } } if(i==n && g) { for(i=1;i<n;i++) { printf("%d",a[i]); } printf("%d\n",a[i]); } if(i<n && g) { i++; a[i]=1;

continue; } while(a[i]==n && i>1) { i--; } if(a[i]==n && i==1) { break; } else { a[i]++; } } } return 0; }

Problem E: Let the Balloon Rise
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 2838 Solved: 1102

Description
Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color and find the result. This year, they decide to leave this lovely job to you.

Input
Input contains multiple test cases. Each test case starts with a number N (0 < N <= 1000) -- the total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters. A test

case with N = 0 terminates the input and this test case is not to be processed.

Output
For each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case.

Sample Input
5 green red blue red red 3 pink orange pink 0

Sample Output
red pink

HINT
#include<stdio.h> #include<string.h> char a[1000][15]; int b[1000];

int main() { int n,i,j,max,k; while(scanf("%d",&n)!=EOF) { if(n==0) break; for(i=1;i<=n;i++) { } { { } } max=b[1]; k=1; for(i=2;i<=n;i++) { if(b[i]>max) { max=b[i]; k=i; } } printf("%s\n",a[k]); } return 0; } b[i]=0; for(i=1;i<=n;i++) for(j=1;j<=n;j++) b[i]++; scanf("%s",a[i]); //二维数组的神奇用法

if(strcmp(a[i],a[j])==0)

Problem A: 深入浅出学算法 002-n 个 1
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 2170 Solved: 737

Description

Input

Output

Sample Input
1 11

Sample Output
2

HINT

#include<stdio.h> int main() { int T,k,n,i,r,m,z; while(scanf("%d",&T)!=EOF) { for(i=1;i<=T;i++) { n=1; r=1; scanf("%d",&k); while(r!=0) { m=r*10+1;

r=m%k; n++; } printf("%d\n",n); } } }

Problem A: 数字菱形
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 4241 Solved: 2642

Description

Input

Output

Sample Input
3

6

Sample Output
1 222 33333 222 1

1 222 33333 4444444 555555555 66666666666 555555555 4444444 33333 222 1

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

printf("%d",i); printf("\n"); } for(a=1;a<n;a++) { for(b=1;b<=a;b++) printf(" "); for(b=1;b<=2*(n-a)-1;b++) printf("%d",n-a); printf("\n"); }} return 0; }

Problem B: 保卫钓鱼岛
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1736 Solved: 974

Description

Input

Output

Sample Input

2 3 670 980 230 4 90 87 76 960

Sample Output
980 670 230 960 90 87 76

#include<stdio.h> int main() { int i,j,t,n,m; int a[101]; scanf("%d",&m); for(i=1;i<=m;i++) { scanf("%d",&n); for(i=1;i<=n;i++){ scanf("%d",&a[i]); } for(i=1;i<=n;i++){ for(j=i;j<=n;j++){ if(a[j]>a[i]){ t=a[i]; a[i]=a[j]; a[j]=t; } else continue; }} for(i=1;i<=n;i++){ if(i!=n)

printf("%d ",a[i]); else printf("%d\n",a[i]); } } return 0; }

Problem D: 基因分裂
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 2582 Solved: 1160

Description

Input

Output

Sample Input
2 4 5 0

Sample Output

2 4 6

#include <stdio.h> int main() { int n,i; int a[55]={0}; while(scanf("%d",&n)!=EOF&&(n!=0)) { a[1]=1; a[2]=2; a[3]=3; a[4]=4; a[5]=6; for(i=5;i<=n;i++) a[i]=a[i-1]+a[i-3]; printf("%d\n",a[n]); } return 0; }

Problem E: 碉堡
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 476 Solved: 294

Description

Input

Output

Sample Input
4 .X.. .... XX.. .... 2 XX .X 3 .X. X.X .X. 3

... .XX .XX 4 .... .... .... .... 0

Sample Output
5 1 5 2 4

Problem C: 最大盈利
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 1727 Solved: 487

Description

Input

Output

Sample Input
2 5 6 -1 5 4 -7 7 0 6 -1 1 -6 7 -5

Sample Output
Payoff 1: 14 1 4

Payoff 2: 7 1 6

Problem B: 绝配队伍
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 7847 Solved: 4236

Description

Input

Output

Sample Input
153 610

Sample Output

Yes No

HINT

#include<stdio.h> int main() { int n,a,b,c; while(scanf("%d",&n)!=EOF) { a=n/100; b=n/10%10; c=n%10; if(a*a*a+b*b*b+c*c*c==n) printf("Yes\n"); else printf("No\n"); } }

Problem D: 超级楼梯
Time Limit: 1 Sec Memory Limit: 64 MB Submit: 353 Solved: 287

Description

Input

Output

Sample Input
2 2 3

Sample Output
1 2

#include<stdio.h> int main() { int n,m,i,j,a[10000]; scanf("%d",&n); { for(i=1;i<=n;i++) { scanf("%d",&m); a[1]=1; a[2]=2; for(j=3;j<=m-1;j++) a[j]=a[j-1]+a[j-2]; printf("%d\n",a[m-1]); } } }

Problem C: 幸运日
Time Limit: 1 Sec Memory Limit: 128 MB Submit: 828 Solved: 127

Description
6 是 1 个神奇的数字。 小明认为以这个月 1 日开始计算，距离基础日天数是 6、含有 6 或是 6 的倍数的日 子都是幸运日，比如本月 6 号，12 日等都是。不过这个幸运日只能持续 200 天， 200 天后的基数日要重新选择。现在告诉你今天是几号，你能帮小明找出剩下的所 有幸运日吗？你只需列出距离基础日（即本月 1 日）的天数即可。

Input

Output

Sample Input
1 3

Sample Output
6 12 16 18 24 26 30 36...

HINT

#include<stdio.h> int main() {

int n,m,i,j; scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&m); if(m>6) { for(j=m;j<=200;j++) if(j%6==0||j%10==6||j/10==6) printf("%d ",j); printf("\n"); } if(m<=6) { for(j=m;j<=200;j++) if(j%6==0||j%10==6||j/10==6) printf("%d ",j); printf("\n"); } } return 0; }

最优化算法课后习题标准版(第三章)_图文

(清华大学)陈宝林最优化算法第三章标准答案 第三章—单纯形方法题解 1 (清华大学)陈宝林最优化算法第三章标准答案 2 (清华大学)陈宝林最优化算法第三章标准答案...

2014-2015学年第2学期算法与数据结构(AB)试题与标准答案

2014-2015学年第2学期算法与数据结构(AB)试题与标准答案_教学计划_教学研究_教育...2 2014-2015 学年第 2 学期《算法与数据结构》试题(A) 参考解答及评分标准...