1、32.多项式求和33.人口问题34.数字菱形Climb the Taishan Mountain(II)Time Limit:1000MS Memory Limit:65536KTotal Submit:753 Accepted:495DescriptionLabor day is coming.Since the holiday is long,Many students are planning to have a tour. The Taishan Mountain is very beautiful, so WangPeng and his classmates want to cli
2、mb the Taishan Mountain. Mountaineering sports is WangPengs avocation, so he is very excited. Suddenly, a very amusing idea comes to him. The Taishan Mountain has many stairs, and he can climb the mountain one step by 2 stairs or by 1 stairs. How many ways does he have to climb the mountain? For exa
3、mple, the stairs is 2, he has 2 ways.The first one is the first step by 1 stair, and the next step by 1 stair.And the second way is only one step by 2 stairs. InputThe input is including many test cases. Every line is one test case with a integer number N(N=40). N is the stairs of the Taishan Mounta
4、in. OutputYou should output how many ways WangPeng can climb the mountain, each case output a line.Sample Input123Sample Output#includeint main() int n,i,j,a41; while(scanf(%d,&n)!=EOF) a0=1; a1=2; for(i=2;i40;i+) ai=ai-1+ai-2; printf(%dn,an-1);Peach689 Accepted:Almost all young man know Monkey Sun
5、whose name is Sun Wukong. One day he steals many peaches from the kingdom of heaven. First day, he ate a half of the peaches, then ate another one of the left peaches.The next day, he ate a half of the left peaches, then another one.Until the n-th day ,before he ate he found only one peach. Please h
6、elp Sun Wukong to calculate how many peaches he took from the kingdom of heaven.The input file contains one or more test cases, each line is the days N(1 n 30).For each test case, output a line indicating the number of peaches Monkey Sun had the first day.422 int n,t,i,s; t=1; s=0; for(i=0;n-1; s=(t
7、+1)*2; t=s;,t);循环练习a+bC语言初学者百题大战之二十二3739 Accepted:2513终于到循环结构了。现在开始你可以做很多事情了。 现在我们开始第一个循环题目计算a+b.很多的题目测试数据会有很多组的,一般我们的在线系统没写具体要求的时候,输入是以EOF为结束的。这题的基本框架如下: int a,b;%d%da,&b)!=EOF) /特别注意这行的写法 ./求和 ./输出scanf函数是有返回值的,如果从键盘上成功读入一个数,那么返回值就是1,如果成功读入2个,则返回2。如果处理到文件末尾,则返回EOF特别注意:题目的要求实际上是指每组数据输入结束后,马上输出这组的结果
8、,而不是等所有数据输完后才输出结果输入为多组测试数据。每组一行,每行输入2个整数a和b对于每组测试数据,输出一行,输出a+b的值,直到文件末尾2 34 57 85915,a+b);新郎新娘1659 Accepted:1069Labor day is long, and many young people will have their wedding between 1st,May and 7th, May. Yesterday, three young couples took photos beside the West Lake. The three bridegroom is A, B
9、, C, and the three bride is X, Y, Z. Mary asked them to know who are the couples.She asked three of them. A said he will marry to X. X said that her young man is C. And C said he will marry to Z. Mary know what all they said is wrong.Since you are very smart, she asks you to help her to find who is
10、the bride of A, who is the bride of B, and who is the bride of C?No Input.Output three lines. the first line is the bride of A, the second line is the bride of B, the third line is the bride of C.XYZ(May no the sequence) int x,y,z; for(x=1;x=3;x+) for(y=1;yy+) z=6-x-y; if(x!=y&x!=z&y!=3&z!=1) if(x=1
11、)Xn); if(y=1)Yn if(z=1)Zn if(x=2) if(y=2) if(z=2) if(x=3) if(y=3) if(z=3)最大公约数和最小公倍数2745 Accepted:1398Given 2 positive integer x(1=x=1000) and y(1=yy) t=x; x=y; y=t; for(i=x;i0;i-) if(x%i=0&y%i=0) a=i; break; b=(x*y)/a;%d %dn,a,b);查找某一个数1118 Accepted:551输入一个从小到大排列的有序数列(长度小于100),在此数列中查找某一个数x,若找到,输出相应
12、下标,否则,输出”Not Found.多组测试数据,先输入要查找的数x和n, 再输入n个有序数。输出x所在位置下标或Not Found2 8 -2 2 3 8 9 20 25 675 7 -2 2 3 8 9 20 25 Not Found int n,x,a100,i,s,j;x)! scanf(n);n;ai); s=-1; for(j=0;jj+) if(aj=x),j); s=j; if(s=-1)Not Foundn偶数排序630 Accepted:433输入一个正整数N和N个整数,将它们中的偶数按从大到小的顺序进行排序后输出。多组测试数据,每组输入一个正整数N(1N100)和N个整
13、数,用空格分隔。将这N个数中的偶数按从大到小的顺序输出10 8 4 14 2 11 30 40 500 17 1008 80 200 99 -12 34 55 88 11500 100 40 30 14 8 4 2200 88 80 34 -12 int n,m,j,q,p,i,b10000,a10000,r,e;bi); e=0; for(r=0;rr+) if(br%2=0) ae=br; e=e+1; m=a0;e-1; for(q=j+1;qaj) m=aq; aq=aj; aj=m; for(p=0;pp+)%d ,ap);,ae-1);N个数从大到小排序1787 Accepted:
14、1254输入一个正整数N和N个整数,将它们按从大到小的顺序进行排序后输出。将这N个数按从大到小的顺序重新输出。10 -4 5 12 88 23 -9 2 0 8 105 12 3 4 9 -2 88 23 12 10 8 5 2 0 -4 -912 9 4 3 -2 int n,m,j,q,p,i,a10000;N个数从小到大排序2443 Accepted:1289输入一个正整数N和N个整数,将它们按从小到大的顺序进行排序后输出。将这N个数按从小到大的顺序重新输出 5 12 3 4 9 -2-9 -4 0 2 5 8 10 12 23 88-2 3 4 9 12 if(aq逆序输出数列345 Accepted:282输入一个正整数n(n1j-),aj);,a0);逆序数544 Accepted:365输入一个任意整数(int型),输出其位数并逆序输出该数。多组测试数据,每组输入一个任意整数(int型)输出其位数及逆序数12345-12354321 5-321 3 int n,w,a10000,j,i; w=n; if(n0) n=-n;100000; ai=n%10; if(n=0) n=n/10; if(w-i; %dn,i);计算高度519 Accepted:321Descripti
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1