完整word版杭电ACM试题答案

合集下载

(完整版)杭电acm部分答案

(完整版)杭电acm部分答案

Problem DescriptionCalculate A + B.InputEach line will contain two integers A and B. Process to end of file.OutputFor each case, output A + B in one line.Sample Input1 1Sample Output2#include<stdio.h>void main(){int a,b;while(scanf("%d %d",&a,&b)!=EOF){printf("%d\n",a+b);}}Problem DescriptionHey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.InputThe input will consist of a series of integers n, one integer per line.OutputFor 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 Input1100Sample Output15050#include<stdio.h>void main(){int n,sum,i;while(scanf("%d",&n)!=EOF){sum=0;for( i=0;i<=n;i++)sum+=i;printf("%d\n\n",sum);}}Problem DescriptionI have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.InputThe first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.OutputFor each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.Sample Input21 2112233445566778899 998877665544332211Sample OutputCase 1:1 +2 = 3Case 2:112233445566778899 + 998877665544332211 = 1111111111111111110 #include<stdio.h>#include<string.h>int main(){char str1[1001], str2[1001];int t, i, len_str1, len_str2, len_max, num = 1, k;scanf("%d", &t);getchar();while(t--){int a[1001] = {0}, b[1001] = {0}, c[1001] = {0};scanf("%s", str1);len_str1 = strlen(str1);for(i = 0; i <= len_str1 - 1; ++i)a[i] = str1[len_str1 - 1 - i] - '0';scanf("%s",str2);len_str2 = strlen(str2);for(i = 0; i <= len_str2 - 1; ++i)b[i] = str2[len_str2 - 1 - i] - '0';if(len_str1 > len_str2)len_max = len_str1;elselen_max = len_str2;k = 0;for(i = 0; i <= len_max - 1; ++i){c[i] = (a[i] + b[i] + k) % 10;k = (a[i] + b[i] + k) / 10;}if(k != 0)c[len_max] = 1;printf("Case %d:\n", num);num++;printf("%s + %s = ", str1, str2);if(c[len_max] == 1)printf("1");for(i = len_max - 1; i >= 0; --i){printf("%d", c[i]);}printf("\n");if(t >= 1)printf("\n");}return 0;}Problem DescriptionGiven a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.InputThe first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line starts with a number N(1<=N<=100000), then N integers followed(all the integers are between -1000 and 1000).OutputFor each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line contains three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end position of the sub-sequence. If there are more than one result, output the first one. Output a blank line between two cases.Sample Input25 6 -1 5 4 -77 0 6 -1 1 -6 7 -5Sample OutputCase 1:14 1 4Case 2:7 1 6注:最大子序列是要找出由数组成的一维数组中和最大的连续子序列。

计算机acm试题及答案

计算机acm试题及答案

计算机acm试题及答案一、选择题1. 在计算机科学中,ACM代表什么?A. 人工智能与机器学习B. 计算机辅助制造C. 计算机辅助设计D. 国际计算机学会答案:D2. 下列哪个不是计算机程序设计语言?A. PythonB. JavaC. C++D. HTML答案:D3. 在计算机系统中,CPU代表什么?A. 中央处理单元B. 计算机辅助设计C. 计算机辅助制造D. 计算机辅助教学答案:A二、填空题1. 计算机的内存分为__________和__________。

答案:RAM;ROM2. 在编程中,__________是一种用于存储和操作数据的数据结构。

答案:数组3. 计算机病毒是一种__________,它能够自我复制并传播到其他计算机系统。

答案:恶意软件三、简答题1. 请简述计算机操作系统的主要功能。

答案:计算机操作系统的主要功能包括管理计算机硬件资源,提供用户界面,运行应用程序,以及控制其他系统软件和应用软件的运行。

2. 什么是云计算,它与传统的本地计算有何不同?答案:云计算是一种通过互联网提供计算资源(如服务器、存储、数据库、网络、软件等)的服务模式。

与传统的本地计算相比,云计算允许用户按需获取资源,无需购买和维护物理硬件,具有更高的灵活性和可扩展性。

四、编程题1. 编写一个程序,计算并输出从1到100(包括1和100)之间所有偶数的和。

答案:```pythonsum = 0for i in range(1, 101):if i % 2 == 0:sum += iprint(sum)```2. 给定一个字符串,编写一个函数,将字符串中的所有字符按ASCII 码值排序并返回。

答案:```pythondef sort_string(s):return ''.join(sorted(s))```五、论述题1. 论述计算机硬件和软件之间的关系及其对计算机系统性能的影响。

答案:计算机硬件是计算机系统的物质基础,包括CPU、内存、硬盘等,而软件则是运行在硬件上的程序和数据。

ACM试题及参考答案

ACM试题及参考答案

1. 给定一个矩阵M(X, Y),列集为X ,行集为Y 。

如果存在对其列的一个排序,使得每一行的元素都严格递增,称M 是一个次序保持矩阵。

例如下图中存在一个排序x 4,x 1,x 2,x 3,x 5I ⊆X ,满足:子矩阵M(I,Y)是次序保持矩阵。

[测试数据] 矩阵M :[测试数据结果] I={ x 1,x 3,x 4,x 7,x 8}[解题思路] 将该问题归约为在一个有向图中找一条最长路径的问题。

给定矩阵M=(a ij ),行集Y ,列集X ,行子集J ⊆Y ,定义有向图D A =(V A ,E A ),其中V A 含有|X|个顶点,每个顶点代表X 中的一列,如果顶点u ,v 对应的列x u ,x v 满足,对于任意的j ∈J ,u v ij ij a a <,则有一条从u 到v 的弧(u ,v )∈E 。

显然,D A 是个无环图,可以在O(|X|2)时间内构造完毕。

对于任意的条件子集J ,A(I,J)是次序保持的当且仅当对应于J 中条件的顶点在D A 中构成一条有向路径。

从而我们只需在有向图D A 中找一条最长路径,该问题可在O(|V A |+| E A |)时间内完成。

按上面的方法构造有向图如下:有向图中找最长路径的线性时间算法。

一些表示方法如下:d out (u )为顶点u 的出度,d in (u )为顶点u 的入度,source 为入度为0的顶点,sink 为出度为0的顶点,N out (u )为u 指向的邻接点集合,P uv 为从u 到v 的最长路,显然应从source 到sink 。

在每一步为每个顶点关联一个永久的或临时的标签。

v被赋了一个临时标签(v’,i v)表明在当前步,算法找出的最长的从source到v的有向路长度为i v,且经由v’而来。

v被赋了一个永久标签[v’,i v]表明从source到v的最长有向路长度为i v,且经由v’而来,通过回溯每个顶点的永久标签就可以找出最长有向路。

acm竞赛试题及答案

acm竞赛试题及答案

acm竞赛试题及答案ACM竞赛试题及答案1. 问题描述:给定一个整数数组,找出数组中没有出现的最小的正整数。

2. 输入格式:第一行包含一个整数n,表示数组的长度。

第二行包含n个整数,表示数组的元素。

3. 输出格式:输出一个整数,表示数组中没有出现的最小的正整数。

4. 样例输入:53 4 1 2 55. 样例输出:66. 问题分析:首先,我们需要理解题目要求我们找出数组中缺失的最小正整数。

这意味着我们需要检查数组中的每个元素,并确定最小的正整数是否在数组中。

7. 算法描述:- 遍历数组,使用一个哈希集合记录出现的数字。

- 从1开始,检查每个正整数是否在哈希集合中,直到找到不在集合中的最小正整数。

8. 代码实现:```pythondef find_missing_positive(nums):seen = set()for num in nums:if num <= 0:continuewhile num in seen or num > len(nums):num += 1seen.add(num)return min(set(range(1, len(nums) + 1)) - seen)```9. 测试用例:- 输入:[3, 4, -1, 1]- 输出:210. 答案解析:在给定的测试用例中,数组[3, 4, -1, 1]中没有出现的最小正整数是2。

这是因为-1不是正整数,所以可以忽略。

数组中已经出现了1和3,所以下一个最小的正整数就是2。

11. 注意事项:- 确保数组中的元素是整数。

- 考虑数组中可能包含0或负数的情况。

- 算法的时间复杂度应尽可能低。

12. 扩展思考:- 如果数组非常大,如何优化算法?- 如果数组中的元素可以是浮点数,算法应该如何修改?13. 参考答案:- 针对大数组,可以考虑使用更高效的数据结构,如平衡二叉搜索树。

- 如果元素是浮点数,需要先将其转换为整数,然后再进行处理。

整理出ACM所有题目及答案

整理出ACM所有题目及答案

1000 A + B ProblemProblem DescriptionCalculate A + B.InputEach line will contain two integers A and B. Process to end of file.OutputFor each case, output A + B in one line.Sample Input1 1Sample Output2AuthorHDOJ代码:#include<stdio.h>int main(){int a,b;while(scanf("%d %d",&a,&b)!=EOF)printf("%d\n",a+b);}1001 Sum ProblemProblem DescriptionHey, welcome to HDOJ(Hangzhou Dianzi University Online Judge).In this problem, your task is to calculate SUM(n) = 1 + 2 + 3 + ... + n.InputThe input will consist of a series of integers n, one integer per line.OutputFor 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 Input1100Sample Output15050AuthorDOOM 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);}}1002 A + B Problem IIProblem DescriptionI have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B. InputThe first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000. OutputFor each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.Sample Input21 2112233445566778899 998877665544332211Sample OutputCase 1:1 +2 = 3Case 2:112233445566778899 + 998877665544332211 = 1111111111111111110AuthorIgnatius.L代码:#include <stdio.h>#include <string.h>int main(){char str1[1001], str2[1001];int t, i, len_str1, len_str2, len_max, num = 1, k;scanf("%d", &t);getchar();while(t--){int a[1001] = {0}, b[1001] = {0}, c[1001] = {0}; scanf("%s", str1);len_str1 = strlen(str1);for(i = 0; i <= len_str1 - 1; ++i)a[i] = str1[len_str1 - 1 - i] - '0';scanf("%s",str2);len_str2 = strlen(str2);for(i = 0; i <= len_str2 - 1; ++i)b[i] = str2[len_str2 - 1 - i] - '0';if(len_str1 > len_str2)len_max = len_str1;elselen_max = len_str2;k = 0;for(i = 0; i <= len_max - 1; ++i){c[i] = (a[i] + b[i] + k) % 10;k = (a[i] + b[i] + k) / 10;}if(k != 0)c[len_max] = 1;printf("Case %d:\n", num);num++;printf("%s + %s = ", str1, str2);if(c[len_max] == 1)printf("1");for(i = len_max - 1; i >= 0; --i){printf("%d", c[i]);}printf("\n");if(t >= 1)printf("\n");}return 0;}1005 Number Sequence Problem DescriptionA number sequence is defined as follows:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.Given A, B, and n, you are to calculate the value of f(n).InputThe input consists of multiple test cases. Each test case contains 3 integers A, B and n on a single line (1 <= A, B <= 1000, 1 <= n <= 100,000,000). Three zeros signal the end of input and this test case is not to be processed. OutputFor each test case, print the value of f(n) on a single line.Sample Input1 1 31 2 100 0 0Sample Output25AuthorCHEN, ShunbaoSourceRecommendJGShining代码:#include<stdio.h>int f[200];int main(){int a,b,n,i;while(scanf("%d%d%d",&a,&b,&n)&&a&&b&&n){if(n>=3){f[1]=1;f[2]=1;for(i=3;i<=200;i++){f[i]=(a*f[i-1]+b*f[i-2])%7;if(f[i-1]==1&&f[i]==1)break;}i-=2;n=n%i;if(n==0)printf("%d\n",f[i]);elseprintf("%d\n",f[n]);}elseprintf("1\n");}return 0;}1008 ElevatorProblem DescriptionThe highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.InputThere are multiple test cases. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100. A test case with N = 0 denotes the end of input. This test case is not to be processed.OutputPrint the total time on a single line for each test case.Sample Input1 23 2 3 1Sample Output1741AuthorZHENG, JianqiangSourceRecommendJGShining代码:#include<stdio.h>int a[110];int main(){int sum,i,n;while(scanf("%d",&n)&&n!=0){for(i=1;i<=n;i++)scanf("%d",&a[i]);sum=0;a[0]=0;for(i=1;i<=n;i++){if(a[i]>a[i-1])sum+=6*(a[i]-a[i-1]);elsesum+=4*(a[i-1]-a[i]);sum+=5;}printf("%d\n",sum);}return 0;}1009 FatMouse' TradeProblem DescriptionFatMouse prepared M pounds of cat food, ready to trade with the cats guarding the warehouse containing his favorite food, JavaBean.The warehouse has N rooms. The i-th room contains J[i] pounds of JavaBeans and requires F[i] pounds of cat food. FatMouse does not have to trade for all the JavaBeans in the room, instead, he may get J[i]* a% pounds of JavaBeans if he pays F[i]* a% pounds of cat food. Here a is a real number. Now he is assigning this homework to you: tell him the maximum amount of JavaBeans he can obtain.InputThe input consists of multiple test cases. Each test case begins with a line containing two non-negative integers M and N. Then N lines follow, each contains two non-negative integers J[i] and F[i] respectively. The last test case is followed by two -1's. All integers are not greater than 1000.OutputFor each test case, print in a single line a real number accurate up to 3 decimal places, which is the maximum amount of JavaBeans that FatMouse can obtain.Sample Input5 3 7 2 4 3 5 2 20 3 25 18 24 15 15 10 -1 -1Sample Output13.333 31.500AuthorCHEN, YueSourceRecommendJGShining代码:#include<stdio.h>#include<string.h>#define MAX 1000int main(){int i,j,m,n,temp;int J[MAX],F[MAX];double P[MAX];double sum,temp1;scanf("%d%d",&m,&n);while(m!=-1&&n!=-1){sum=0;memset(J,0,MAX*sizeof(int));memset(F,0,MAX*sizeof(int));memset(P,0,MAX*sizeof(double));for(i=0;i<n;i++){ scanf("%d%d",&J[i],&F[i]); P[i]=J[i]*1.0/((double)F[i]); }for(i=0;i<n;i++){for(j=i+1;j<n;j++){if(P[i]<P[j]){temp1=P[i]; P[i]=P[j]; P[j]=temp1;temp=J[i]; J[i]=J[j]; J[j]=temp;temp=F[i]; F[i]=F[j]; F[j]=temp;}}}for(i=0;i<n;i++){if(m<F[i]){ sum+=m/((double)F[i])*J[i]; break; }else { sum+=J[i]; m-=F[i]; }}printf("%.3lf\n",sum); scanf("%d%d",&m,&n);}return 0;}1021 Fibonacci Again Problem DescriptionThere are another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2). InputInput consists of a sequence of lines, each containing an integer n. (n < 1,000,000).OutputPrint the word "yes" if 3 divide evenly into F(n).Print the word "no" if not.Sample Input12345Sample OutputnonoyesnononoAuthorLeojayRecommendJGShining#include<stdio.h>int main(){long n;while(scanf("%ld",&n) != EOF)if (n%8==2 || n%8==6)printf("yes\n");elseprintf("no\n");return 0;}1089 A+B for Input-Output Practice (I) Problem DescriptionYour 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.InputThe input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line. OutputFor 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 Input1 510 20Sample Output630AuthorlcyRecommendJGShining解答:#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 DescriptionYour task is to Calculate a + b.InputInput 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.OutputFor 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 Input21 510 20Sample Output630AuthorlcyRecommendJGShining解答:#include<stdio.h>#define M 1000void 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 DescriptionYour task is to Calculate a + b.InputInput 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.OutputFor 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 Input1 510 200 0Sample Output630AuthorlcyRecommendJGShining解答:#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 DescriptionYour task is to Calculate the sum of some integers.InputInput 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.OutputFor each group of input integers you should output their sum in one line, and with one line of output for each line in input.。

(完整版)浙江工业大学ACM

(完整版)浙江工业大学ACM

浙江工业大学ACM部分程序解读●程序设计导引及在线实践●最重要的是边界:输入的边界和输出的边界:●if(n==0)cout<〈” 0-—>0”<<endl;//一定要考虑最特殊的情况●cout.precision(3); cout<<fixed<〈sum<〈endl; printf("%.3f\n",sum);//以后的采用●时刻请注意清空,向量及变量Zjut1002数字游戏#include <iostream〉using namespace std;int divide(int x, int y,int& k){if(x==y) return k;if(x%y==0){k++;return divide(x/y,y,k);}return 1;}int main(){int n,i,x,k,ki;while(scanf(”%d",&n)&&n!=0){ki=k=1;x=n;for(i=2; i<n; i++)if(n%i==0){k=divide(n,i,k);if(k!=1){x=i;ki=k;//importantk=1;//importantcontinue;}}//outif(ki==1)printf("%d %d\n”,0,0);elseprintf("%d %d\n”,x,ki);}return 0;}1010诡秘的余数#include <iostream>#include <string>using namespace std;int quyu(string s,int n){int m=0;for(int i=0;i〈s.size();i++){m=(m*10+s[i]-48)%n;}return m;}int main(){string s;int n;while(cin〉>s>〉n){cout〈〈quyu(s,n)<〈endl;}return 0;}1015简单的事情#include〈iostream〉using namespace std;int main(){int n,m,i,j,k;long nn;while(cin〉〉n〉〉m){if(n==m)cout〈<1〈<endl;else{if(m>n/2){m=n-m;}nn=1;for(i=n,j=0,k=1;j〈m;i——,j++,k++){nn=nn*i/k;}cout<<nn<〈endl;}}return 0;}1016折纸游戏#include 〈iostream>using namespace std;int main(){int n,m,i,j,k,s,t;int a[100][100];cin>〉n;for(i=0;i<n;i++){cin〉〉m;for(j=1;j<=m;j++){for(k=1;k<=m;k++){cin〉〉a[j][k];}}if(m%2==0){for(j=1;j<=m;j++){t=1;s=m;while(t〈m){if(a[j][t]!=a[j][s]){cout<<”no"〈<endl;goto RL;}t++;s-—;}}for(j=1;j〈=m;j++){t=1;s=m;while(t<m){if(a[t][j]!=a[s][j]){cout<<"no”〈〈endl;goto RL;}t++;s--;}}}else{for(j=1;j<=m;j++){t=1;s=m;while(t!=(m+1)/2){if(a[j][t]!=a[j][s]){cout<〈”no”〈<endl;goto RL;}t++;s--;}}for(j=1;j<=m;j++){t=1;s=m;while(t!=(m+1)/2){if(a[t][j]!=a[s][j]){cout〈〈”no"〈<endl;goto RL;}t++;s--;}}}cout〈〈”yes”<<endl;RL:continue;}return 0;}1021ACMICPC#pragma warning(disable:4786)#include <iostream>#include 〈string>#include 〈map〉using namespace std;int max_sum(int a[],int n,int &besti,int &bestj){int i,j,tsum,sum;tsum=0;sum=0;besti=0;bestj=0;i=1;for(j=1;j〈=n;j++){tsum=tsum+a[j];if(tsum>sum){sum=tsum;besti=i;bestj=j;}else if(tsum〈0){i=j+1;tsum=0;}}return sum;}int main(){map<char,int> m;int a[1002];string s;int i,n,j,k,ii,jj,flag,min;m['A']=—13;m['G’]=—7;m[’M']=-1;m['R’]=4;m[’B']=—12;m[’H']=—6;m[’N']=0;m[’S']=5;m['C’]=—11;m['I']=-5;m['O']=1;m[’T’]=6;m['D’]=-10;m['J']=—4;m['P']=2;m['U']=7;m[’E']=-9;m[’K']=-3;m['Q’]=3;m[’V']=8;m[’F’]=—8;m[’L’]=-2;m[’W’]=9;m[’X’]=10;m['Y']=11;m[’Z’]=12;cin>>n;for(i=0;i<n;i++){cin〉〉s;k=1;flag=0;for(j=0;j<s.size();j++){a[k++]=m[s[j]];if(a[k-1]〉0){//一定是k-1flag=1;}}if(flag==0){min=a[1];for(j=2;j〈k;j++){if(a[j]>min){min=a[j];cout<<a[j]〈〈” ”;}}cout〈<min〈<endl;}else{cout〈<max_sum(a,k—1,ii,jj)<〈endl;//cout<<ii<<” "〈〈jj〈<endl;}flag=0;}return 0;}1022IOI#pragma warning(disable:4786)#include <iostream>#include <string〉#include <algorithm>#include <set>using namespace std;int main(){int n,i;string s,ss;set<string〉 sss;set〈string>::iterator it;cin>>n;for(i=0;i〈n;i++){cin>>s;sss.clear();ss=s;reverse(ss.begin(),ss.end());if(ss==s)sss。

(完整word版)杭州电子科技大学计算机网络试卷+答案

(完整word版)杭州电子科技大学计算机网络试卷+答案

(完整word版)杭州电子科技大学计算机网络试卷+答案杭州电子科技大学学生考试卷( B )卷考试课程计算机网络及应用考试日期年月日成绩课程号B0503450 教师号任课教师姓名胡昔祥考生姓名学号(8位)年级专业(答案写在第四页上,写明学生姓名、学号、班级)一单项选择(每空2分,共40分)1、以下给出的地址中,属于子网192.168.15.19/28 的主机地址是________ 。

A、192.168.15.17B、192.168.15.14C、192.168.15.16D、192.168.15.312、关于ICMP的论述,不正确的是_______。

A、ICMP协议典型用途是差错报告B、ICMP报文是封装在IP分组中,因此它和TCP协议一样都是传输层协议C、ping程序实际上向目标主机发送了一个ICMP类型8编码0的报文D、当某IP分组TTL为零时,路由器将丢弃改分组并发送一个ICMP报告给源主机3、关于DHCP的论述,正确的是____________。

A、DHCP只能可动态获取一个IP地址B、DHCP只能可动态获取一个IP地址和它的子网掩码C、DHCP只能可动态获取一个IP地址和默认网关D、DHCP可动态获取一个IP地址、以及它的子网掩码、默认网关和DNS服务器地址4、下列IP地址中为有效私有地址的是__________。

A、201.1.2.1B、110.1.2.1C、192.168.1.2D、172.161.2.35、TCP连接建立的三次握手过程是_________。

A、TCP RST, TCP SYNACK,TCP ACKB、TCP SYN, TCP FINACK, TCP ACKC、TCP SYN, TCP SYNACK, TCP ACKD、TCP PSH, TCP SYNACK, TCP ACK6、滑动窗口协议中,发送窗口保存的是_____________。

A、可发送的帧序号B、可接收的帧序号C、不可发送的帧序号D、不可接收的帧序号7、在TCP拥塞控制机制中,当拥塞窗口小于阈值时,拥塞窗口呈_________。

ACM入门十题(杭电oj)

ACM入门十题(杭电oj)

ACM入门(杭电oj)Hdu 1000#include<stdio.h>#include<stdlib.h>int main(){int a,b;while(scanf("%d%d",&a,&b)!=EOF){printf("%d\n",a+b);}}Hdu 1001#include<stdio.h>#include<stdlib.h>int main(){int n;while(scanf("%d",&n)!=EOF){printf("%I64d\n\n",(__int64)(1+n)*n/2); }}Hdu 1002#include<stdio.h>#include<string.h>#include<stdlib.h>char str1[1005],str2[10005];int main(){int ca,count=0;scanf("%d",&ca);while(ca--){scanf("%s%s",str1,str2);int a[1005],i,j;memset(a,0,sizeof(a));for(i=strlen(str1)-1,j=0;i>=0;i--,j++)a[j]=str1[i]-'0';for(i=strlen(str2)-1,j=0;i>=0;i--,j++){a[j]=a[j]+str2[i]-'0';a[j+1]=a[j+1]+a[j]/10;a[j]=a[j]%10;}count++;printf("Case %d:\n",count);printf("%s + %s = ",str1,str2); int flag=0;for(i=1004;i>=0;i--)if(flag||a[i]){printf("%d",a[i]);flag=1;}printf("\n");if(ca!=0) printf("\n");}}Hdu 1003#include<stdio.h>#include<stdlib.h>int a[100005],sum[100005];int main(){int ca,count=0;scanf("%d",&ca);while(ca--){int n,i;scanf("%d",&n);for(i=1;i<=n;i++)scanf("%d",&a[i]);sum[1]=a[1];int r=1,max=a[1];for(i=2;i<=n;i++){if(sum[i-1]>0){sum[i]=sum[i-1]+a[i];if(sum[i]>max){max=sum[i];r=i;}}else{sum[i]=a[i];if(sum[i]>max){max=sum[i];r=i;}}}count++;for(i=r-1;i>0;i--)if(sum[i]<0) break;printf("Case %d:\n",count);printf("%d %d %d\n",max,i+1,r); if(ca!=0) printf("\n");}}Hdu 1004#include<iostream>#include<algorithm>using namespace std;struct point{char c[50];}p[1005];int cmp(point p1,point p2){return strcmp(p1.c,p2.c)<0;}int main(){int n,i;while(scanf("%d",&n)!=EOF&&n) {for(i=0;i<n;i++)scanf("%s",p[i].c);sort(p,p+n,cmp);char res[100];strcpy(res,p[0].c);int num=1,ct=1;for(i=1;i<n;i++){if(strcmp(p[i].c,p[i-1].c)==0) num++; else num=1;if(num>ct){strcpy(res,p[i].c);ct=num;}}printf("%s\n",res);}}Hdu 1005#include<stdio.h>#include<stdlib.h>#include<string.h>int s[10][10],c[1000];int main(){c[1]=1;c[2]=1;int a,b,n;while(scanf("%d%d%d",&a,&b,&n)!=EOF){if(a==0&&b==0&&n==0) break;memset(s,0,sizeof(s));s[1][1]=1;int i;for(i=3;;i++){c[i]=(a*c[i-1]+ b*c[i-2])%7;if(s[c[i-1]][c[i]]!=0) break;s[c[i-1]][c[i]]=i-1;}/*for(int j=1;j<=i;j++)printf("%d ",c[j]);*/int m=s[c[i-1]][c[i]]-1;int len=i-1-s[c[i-1]][c[i]];//printf("%d %d\n",m,len);if(n<=m){printf("%d\n",c[n]);continue;}n=n-m;printf("%d\n",c[m+(n%len? n%len:len)]); }}Hdu 1008#include<stdio.h>#include<stdlib.h>int main(){int n;while(scanf("%d",&n)!=EOF&&n){int a,sum=0,st=0,m=n;while(n--){scanf("%d",&a);sum=sum+(a-st>0?(a-st)*6:(st-a)*4); st=a;}printf("%d\n",m*5+sum);}}Hdu 1012#include<stdio.h>int main(){printf("n e\n");printf("- -----------\n");printf("0 1\n");printf("1 2\n");printf("2 2.5\n");printf("3 2.666666667\n");printf("4 2.708333333\n");printf("5 2.716666667\n");printf("6 2.718055556\n");printf("7 2.718253968\n");printf("8 2.718278770\n");printf("9 2.718281526\n");}#include<stdlib.h>#include<string.h>#include<stdio.h>int main(){char s[1000];while(scanf("%s",s)!=EOF){if(strcmp(s,"0")==0) break;int i,t=0;for(i=0;i<strlen(s);i++)t=t+s[i]-'0';printf("%d\n",(t+8)%9+1);}}Hdu 1016#include<stdio.h>#include<string.h>inta[25]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61, 67,71,73};int num[25],flag[25],pri[100],n;void dsf(int x,int y){int i;if(y==n){if(pri[x+1]==1){for(i=1;i<n;i++)printf("%d ",num[i]);printf("%d\n",num[i]);}return;}for(i=2;i<=n;i++)if(flag[i]==0&&pri[x+i]==1){flag[i]=1;num[y+1]=i;dsf(i,y+1);flag[i]=0;}int main(){int ct=0,i;memset(pri,0,sizeof(pri));for(i=0;i<15;i++)pri[a[i]]=1;while(scanf("%d",&n)!=EOF){memset(flag,0,sizeof(flag)); printf("Case %d:\n",++ct);flag[1]=1;num[1]=1;dsf(1,1);printf("\n");}}。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

【杭电ACM1000】
A +
B Problem
Problem Description
Calculate A + B.
Input
Each line will contain two integers A and B. Process to end of file.
Output
For each case, output A + B in one line.
Sample Input
1 1
Sample Output
2
# include <stdio.h>
int main()
{
int a, b;
while(scanf(%d%d, &a, &b)!=EOF)
printf(%d\n, a+b);
return 0;
}
【杭电ACM1001】
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
# include <stdio.h>
int main()
{
int n, i, sum = 0;
while(scanf(%d, &n)!=EOF)
{
for(i=1; i<=n; ++i)
sum = sum + i;
printf(%d\n\n, sum);
sum = 0;
}
return 0;
}
【杭电ACM1002】
A +
B Problem II
Problem Description
I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.
Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers
are very large, that means you should not process them by using 32-bit integer. You may assume
the length of each integer will not exceed 1000.
Output
For each test case, you should output two lines. The first line is Case #:, # means the number of
the test case. The second line is the an equation A + B = Sum, Sum means the result of A + B.
Note there are some spaces int the equation. Output a blank line between two test cases.
Sample Input
2 1 2 112233445566778899 998877665544332211
Sample Output
Case 1: 1 + 2 = 3 Case 2: 112233445566778899 + 998877665544332211 = 1111111111111111110
#include<stdio.h>
#include<string.h>
int shu(char a)
{
return (a-'0');
}
int main(){
char a[1000],b[1000];
int num[1001];
int n,i,j=1,al,bl,k,t;
scanf(%d,&n);
while(n--)
{
getchar();
if(j!=1)
printf(\
);
scanf(%s,a);
al=strlen(a);
scanf(%s,b);
bl=strlen(b);
k=(al>bl)?al:bl;
for(i=0;i<=k;i++)
num[i]=0;
t=k;
for(k;al>0&&bl>0;k--)
{
num[k]+=shu(a[--al])+shu(b[--bl]);
if(num[k]/10)
{
num[k-1]++;
num[k]%=10;
}
}
while(al>0)
{
num[k--]+=shu(a[--al]);
if(num[k+1]/10)
{
num[k]++;
num[k+1]%=10;
}
}
while(bl>0)
{
num[k--]+=shu(b[--bl]);
if(num[k+1]/10)
{
num[k]++;
num[k+1]%=10;
}
}
printf(Case %d:\n,j++);
printf(%s + %s = ,a,b);
for(i=0;i<=t;i++)
{
if(i==0&&num[i]==0)
i++;
printf(%d,num[i]);
}
printf(\
);
}
return 0;
}。

相关文档
最新文档