浙大计算机学院考研复试上机试题及参考答案
2017年计算机学院研究生复试上机考试真题

2017年硕士学位研究生招生复试上机试题考试科目: C语言与数据结构算法上机测试考试时间120分钟注意事项:1、源程序都在D:\TEST文件夹下,请先将该“TEST”文件夹改名为“准考证号_姓名”,其中准考证号是初试时的15位准考证号;2、考试结束后,首先删除VC++ 6.0自动生成的debug文件夹,然后使用压缩软件将上述考生文件夹中所有内容打包(包括里面所有文件,比如工程文件等。
除上述debug文件夹外,不得删除任何考试过程中产生的文件),文件名为“准考证号_姓名.rar”,然后将该文件通过教学系统的学生端的“传文件给教师”功能上传到服务器。
注意:文件上传后,需到监考老师处确认方可离开考场。
如果未经监考老师确认,并且文件由于某种原因上传未成功,考试成绩以0分计。
3、如果已经上传,需要修改然后再上传的,在压缩包的文件名后加编号2、3、4等,形如:“考号_姓名2.rar”、“考号_姓名3.rar”。
在监考老师处确认时,请求监考老师将老文件删除。
4、所有提供的文件(包括C源文件),不得更改文件名,也不得更改其内部结构(详见题目中的红字)。
5、所有程序需要在VC++6.0环境中运行,结果正确方可。
比如,程序填空,不能仅将空填好,而是需要运行程序,进行测试,确保正确。
6、本考试共包括1道程序改错、2道程序填空、3道程序编写题,分数分别为:20、 15、 15、 15、15、20。
7、考试题文字描述见下,C程序见考生文件夹下相应文件。
(1) 给定程序modi.c中,函数fun的功能是:用下面的公式求π的近似值,直到最后一项的绝对值小于指定的数(参数num)为止(该项不包括在结果中):例如,程序运行后,输入0.0001,则程序输出3.1414。
请改正程序中的错误,使它能得出正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!(2) 给定程序blank1.c中,函数fun的功能是:找出100至x(x≤999)之间各位上的数字之和为15的所有整数,然后输出;符合条件的整数个数作为函数值返回。
2011浙江大学复试上机

1001: A+B for Matrices时间限制:1 Sec 内存限制:32 MB提交:931 解决:514题目描述This time, you are supposed to find A+B where A and B are two matrices, and then count the number of zero rows and columns.输入The input consists of several test cases, each starts with a pair of positive integers M and N (≤10) which are the number of rows and columns of the matrices, respectively. Then 2*M lines follow, each contains N integers in [-100, 100], separated by a space. The first M lines correspond to the elements of A and the second M lines to that of B.The input is terminated by a zero M and that case must NOT be processed.输出For each test case you should output in one line the total number of zero rows and columns of A+B.样例输入2 21 11 1-1 -110 92 31 2 34 5 6-1 -2 -3-4 -5 -6样例输出15提示来源2011年浙江大学计算机及软件工程研究生机试真题1002: Grading时间限制:1 Sec 内存限制:32 MB提交:748 解决:189题目描述Grading hundreds of thousands of Graduate Entrance Exams is a hard work. It is even harder to design a process to make the results as fair as possible. One way is to assign each exam problem to 3 independent experts. If they do not agree to each other, a judge is invited to make the final decision. Now you are asked to write a program to help this process.For each problem, there is a full-mark P and a tolerance T(<P) given. The grading rules are: • A problem will first be assigned to 2 experts, to obtain G1 and G2. If the difference iswithin the tolerance, that is, if |G1 - G2| ≤ T, this problem's grade will be the average of G1 andG2.• If the difference exceeds T, the 3rd expert will give G3.• If G3 is within the tolerance with either G1 or G2, but NOT both, then this problem's grade will be the average of G3 and the closest grade.• If G3 is within the tolerance with both G1 and G2, then this problem's grade will be the maximum of the three grades.• If G3 is within the toleranc e with neither G1 nor G2, a judge will give the final grade GJ.输入Each input file may contain more than one test case.Each case occupies a line containing six positive integers: P, T, G1, G2, G3, and GJ, as described in the problem. It is guaranteed that all the grades are valid, that is, in the interval [0, P].输出For each test case you should output the final grade of the problem in a line. The answer must be accurate to 1 decimal place.样例输入20 2 15 13 10 18样例输出14.0提示来源2011年浙江大学计算机及软件工程研究生机试真题1004: Median时间限制:1 Sec 内存限制:32 MB提交:652 解决:168题目描述Given an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1={11, 12, 13, 14} is 12, and the median of S2={9, 10, 15, 16, 17} is 15. The median of two sequences is defined to be the median of the non-decreasing sequence which contains all the elements of both sequences. For example, the median of S1 and S2 is 13.Given two increasing sequences of integers, you are asked to find their median.输入Each input file may contain more than one test case.Each case occupies 2 lines, each gives the information of a sequence. For each sequence, the first positive integer N (≤1000000) is the size of that sequence. Then N integers follow, separated by a space.It is guaranteed that all the integers are in the range of long int.输出For each test case you should output the median of the two given sequences in a line.样例输入4 11 12 13 145 9 10 15 16 17样例输出13提示1005: Graduate Admission时间限制:1 Sec 内存限制:32 MB提交:291 解决:50题目描述It is said that in 2011, there are about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if you could write a program to automate the admission procedure.Each applicant will have to provide two grades: the national entrance exam grade GE, and the interview grade GI. The final grade of an applicant is (GE + GI) / 2. The admission rules are: • The applicants are ranked according to their final grades, and will be admitted one by one from the top of the rank list.• If there is a tied final grade, the applicants will be ranked according to their national entrance exam grade GE. If still tied, their ranks must be the same.• Each applicant may have K choices and the admission will be done according to his/her choices: if according to the rank list, it is one's turn to be admitted; and if the quota of one's most preferred shcool is not exceeded, then one will be admitted to this school, or one's other choices will be considered one by one in order. If one gets rejected by all of preferred schools, then this unfortunate applicant will be rejected.• If there is a tied rank, and if the corresponding applicants are applying to the same school,then that school must admit all the applicants with the same rank, even if its quota will be exceeded.输入Each input file may contain more thanone test case.Each case starts with a line containing three positive integers: N (≤40,000), the total number of applicants; M (≤100), the total number of graduate schools; and K (≤5), the number o f choices an applicant may have.In the next line, separated by a space, there are M positive integers. The i-th integer is the quota of the i-th graduate school respectively.Then N lines follow, each contains 2+K integers separated by a space. The first 2 integers are the applicant's GE and GI, respectively. The next K integers represent the preferred schools. For the sake of simplicity, we assume that the schools are numbered from 0 to M-1, and the applicants are numbered from 0 to N-1.输出For each test case you should output the admission results for all the graduate schools. The results of each school must occupy a line, which contains the applicants' numbers that school admits. The numbers must be in increasing order and be separated by a space. There must be no extra space at the end of each line. If no applicant is admitted by a school, you must output an empty line correspondingly.样例输入11 6 32 1 2 2 2 3100 100 0 1 260 60 2 3 5100 90 0 3 490 100 1 2 090 90 5 1 380 90 1 0 280 80 0 1 280 80 0 1 280 70 1 3 270 80 1 2 3100 100 0 2 4样例输出0 1035 6 7 2 81 4。
浙江大学复试面试题目及答案(yyy版本)

浙江大学计算机考研历年面试问题集专业部分操作系统部分:1 windows/linux使用的文件系统?windows使用的文件系统有:FAT(包括FAT12,FAT16,FAT32),CDFS,UDF,NTFS,DFS(分布式文件系统,用于windows2000/xp服务器上的网络组件)linux使用的文件系统有:ext2,ext3,FAT32 ???????2 虚拟内存?传输协调工作,并为用户提供一个统一的界面和标准的接口,用户通过这一界面实现所需要的从操作以及使用系统资源,使系统中的若干台计算机相互协作以完成共同的任务,有效控制和协调诸任务的并行执行,并向系统提供统一的,有效的接口软件集合。
网络操作系统和分布式操作系统虽然都属于管理分布在不同地理位置上的操作系统,但最大的差别是:网络操作系统工作时必须确认网址,而分布式操作系统则不必知道计算机的确切地址;分布式系统负责整个系统的资源分配,通常能够很好的隐藏系统的内部细节,如对象的物理位置,并发控制,系统故障等。
这些对用户都是透明的。
8 操作系统为什么要用驱动程序?参考912 io调度算法?此题似乎有问题,分解之:IO控制方式:程序IO方式,中断驱动IO控制方式,DMA直接存储器访问方式,IO通道控制方式磁盘调度算法:RSS(随机调度),FIFO,PRI(进程优先级调度),LIFO,SSTF(最短作业优先),SCAN (在磁盘上往复),C-SCAN(一条道路,快速返回),N-step- SCAN(一次N个记录的SCAN),FSCAN13 一个文件重命名和把它直接删除后再重新建立新文件名有何不同?1.物理地址:前者不变,后者变化2.pcb:前者只改了文件名,后者重新建立PCB14 介绍一下os的层次结构?●多数据流:文件的实际内容被当作字节流处理,在NTFS中可以为一个文件定义多个数据流;●通用索引功能:NTFS中,每个文件都有一组属性与之关联.这样,文件管理系统中文件描述的集合组织成一个关系数据库,因而文件可以建立关于任何属性的索引.20 轮转法知道么,用在什么系统?简单介绍下分时操作系统,时间片可等长——简单轮转调度,亦可不等长——多级反馈调度数据结构部分:1 介绍分治算法,回溯算法,动态规划法?弃,其余儿子节点被加入到活节点表中。
浙江大学10年计算机上机题(含答案)

一、A+B题目描述:给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号","隔开。
现在请计算A+B的结果,并以正常形式输出。
输入:输入包含多组数据数据,每组数据占一行,由两个整数A和B组成(-10^9 < A,B < 10^9)。
输出:请计算A+B的结果,并以正常形式输出,每组数据占一行。
样例输入:-234,567,890 123,456,7891,234 2,345,678样例输出:-1111111012346912答案:给大家记住数据吧,如果你是用高进度计算的。
注意:你的结果是否有前缀0;0是否带负号;999 110,000 -90 0-0 -00 -01999 1010,001 -10,000#include<iostream>#include<stdio.h>#include<stdlib.h>#include<string>using namespace std;int main(){string strA,strB;while(cin>>strA>>strB){long numA = 0;for(int i=0; i<=strA.length()-1; i++){if(strA[i] <= '9' && strA[i] >= '0'){numA = numA*10 + strA[i] - '0';}}long numB = 0;for(int//去掉否则出现变量重复i=0; i<=strB.length()-1; i++) {if(strB[i] <= '9' && strB[i] >= '0'){numB = numB*10 + strB[i] - '0';}}if(strA[0] != '-' && strB[0] != '-')//++cout<<numA+numB<<endl;if(strA[0] != '-' && strB[0] == '-')//+-cout<<numA-numB<<endl;if(strA[0] == '-' && strB[0] != '-')//-+cout<<numB-numA<<endl;if(strA[0] == '-' && strB[0] == '-')//--cout<<0-(numA+numB)<<endl;}return 0;}已AC1.//可以用sscanf把字符串转换为int,然后直接加就可以了2.#include <iostream>3.#include <cstdio>4.#include <cstring>5.ing namespace std;7.8.const int Maxn = 50;9.int main()10.{11. char str1[Maxn],str2[Maxn];12. char temp[Maxn];13. int a,b,i,r;14. while(scanf("%s%s",str1,str2)!=EOF)15. {16. int len = strlen(str1);17. memset(temp,0,sizeof(temp));18. r = 0;19. for(i = 0; i<len; i++)20. if(str1[i]!=',')temp[r++] = str1[i];21. sscanf(temp,"%d",&a);22. memset(temp,0,sizeof(temp));23. r = 0;24. for(i = 0; i<strlen(str2); i++)25. if(str2[i]!=',')temp[r++] = str2[i];26. sscanf(temp,"%d",&b);27. cout<<a+b<<endl;28. }29. return 0;30.31.}1.#include<stdio.h>2.#include<stdlib.h>3.int sw(char *a){4. int i=0,c=0;5. while(a[i]){6. if(a[i]>='0'&&a[i]<='9')7. c=c*10+a[i]-'0';8. i++;9. }10. if(a[0]=='-')11. c=-c;12. return c;13.}14.int main(){15. char a[99],b[99];16. int a1,b1,c[99],i=0;17. while(scanf("%s %s",a,b)!=EOF){18. a1=sw(a);19. b1=sw(b);20.21. c[i]=a1+b1;22. i++;}23. for(int j=0;j<i;j++)24. printf("%d\n",c[j]);25. return 0;26.}复制代码AC了二、ZOJ问题题目描述:对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC。
浙江大学计算机学院2007年考研复试上机题

浙江大学计算机学院2007年考研复试上机题题目要求:给定一系列2维平面点的坐标(x, y),其中x和y均为整数,要求用一个最小的长方形框将所有点框在内。
长方形框的边分别平行于x和y坐标轴,点落在边上也算是被框在内。
具体的输入输出格式规定如下:输入格式:测试输入包含若干测试用例,每个测试用例由一系列坐标组成,每对坐标占一行,其中|x|和|y|小于231;一对0 坐标标志着一个测试用例的结束。
注意(0, 0)不作为任何一个测试用例里面的点。
一个没有点的测试用例标志着整个输入的结束。
输出格式:对每个测试用例,在1行内输出2对整数,其间用一个空格隔开。
第1对整数是长方形框左下角的坐标,第2对整数是长方形框右上角的坐标。
输入样例:12 5623 5613 100 012 340 00 0输出样例:12 10 23 5612 34 12 34-----------------------------------------------------------------------#include <iostream>using namespace std;int main(){int x1,y1,x2,y2,x,y;while(cin>>x>>y&&(x||y)){x1=x2=x; y1=y2=y;while(cin>>x>>y&&(x||y))x1=x1<x?x1:x,y1=y1<y?y1:y,x2=x2>x?x2:x,y2=y2>y?y2:y;cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl;}return 0;}Time limit: 1 SecondsTotal Submit: 820 Accepted Submit: 199题目要求:统计一个给定字符串中指定的字符出现的次数具体的输入输出格式规定如下:输入格式:测试输入包含若干测试用例,每个测试用例包含2行,第1行为一个长度不超过5的字符串,第2行为一个长度不超过80的字符串。
浙江大学05计算机上机题

一、A + B题目描述:读入两个小于100的正整数A和B,计算A+B.需要注意的是:A和B的每一位数字由对应的英文单词给出.输入:测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔.当A和B同时为0时输入结束,相应的结果不要输出.输出:对每个测试用例输出1行,即A+B的值.样例输入:one + two =three four + five six =zero seven + eight nine =zero + zero =样例输出:39096答案:#include <iostream>#include <string>using namespace std;int toInteger(string A){if(A=="one")return 1;else if(A=="two")return 2;else if(A=="three")return 3;else if(A=="four")return 4;else if(A=="five")return 5;else if(A=="six")return 6;else if(A=="seven")return 7;else if(A=="eight")return 8;else if(A=="nine")return 9;else if(A=="zero")return 0;elsereturn -1;}int main(){string s[1000];int i=0;while(cin>>s[i]){if(s[i]=="="&&s[i-1]=="zero"&&s[i-3]=="zero")break;i++;}for(int j=0;j!=i;){int num1=0,num2=0;int sum=0;while(s[j]!="+"){if(toInteger(s[j])==-1)return 0;elsenum1=num1*10+toInteger(s[j]);j++;}j++;while(s[j]!="="){if(toInteger(s[j])==-1)return 0;elsenum2=num2*10+toInteger(s[j]);j++;}j++;sum=num1+num2;if(sum==0)return 0;cout<<sum<<endl;}return 1;}之二:#include<stdio.h>#include<string.h>int StoInt(char s[]){if(strcmp(s,"zero")==0) return 0;if(strcmp(s,"one")==0) return 1;if(strcmp(s,"two")==0) return 2;if(strcmp(s,"three")==0) return 3;if(strcmp(s,"four")==0) return 4;if(strcmp(s,"five")==0) return 5;if(strcmp(s,"six")==0) return 6;if(strcmp(s,"seven")==0) return 7;if(strcmp(s,"eight")==0) return 8;if(strcmp(s,"nine")==0) return 9;}int main(){char a[50],b[50];int a1[10],b1[10],top1=-1,top2=-1,i,a2,b2;while(scanf("%s",a)!=EOF){if(strlen(a)==1&&a[0]=='+'){while(scanf("%s",b)!=EOF){if(strlen(b)==1&&b[0]=='='){a2=b2=0;for(i=0;i<=top1;i++){a2=a2*10+a1;}for(i=0;i<=top2;i++){b2=b2*10+b1;}if(a2==b2&&a2==0){break;}else{top1=top2=-1;printf("%d\n",a2+b2);break;}}else{b1[++top2]=StoInt(b);}}}else a1[++top1]=StoInt(a);if(a2==b2&&a2==0) break;}return 0;}AC代码。
浙大计算机研究生英语.复试资料

浙大计算机研究生英语.复试资料1.自我介绍Question: Please introduce yourself.2.介绍自己的家庭。
Q: Please introduce your family.3.请介绍你寝室的室友Q: Could you introduce your classmates of your dormitory?A: Ok, there are six men in my dormitory. Three come from Tianjin, and one from Anhui province, and another from Liaoning province, and I come from Heilongjiang province. The guy from Anhui is the oldest. He knows more, and takes care of us like brothers. And I respect him very much. We are all kind, and enjoy a happy college life together. We visited many interesting places in Tianjin, such as the golden street, ancient culture street, tea house, and so on. We all very like to sit in the tea house to listen to the Tianjin crosstalk. It is very funny. That’s all, thank you.4.请介绍你家乡的历史Q: Introduce the history of your hometown?我的家乡是个新兴的城镇,在建国后成立的。
浙江大学计算机考研真题

牛客网,程序员学求职备考神器
NOWCODER
10、在采用中断 I/O 方式控制打印输出的情况下,CPU 和打印控制接口中的 I/O 端口之间交换的信息不可能是()。(点击查看答案>>>>>>>>) A、打印字符 B、主存地址 C、设备状态 D、控制命令
牛客网,程序员学求职备考神器
NOWCODER
牛在牛客网
测试输入包含若干测试用例。每个测试用例的第 1 行给出评估的道路条数 N、 村庄数目 M (N, M < =100 );随后的 N 行对应村庄间道路的成本,每行给出一 对正整数,分别是两个村庄的编号,以及此两村庄间道路的成本(也是正整数)。 为简单起见,村庄从 1 到 M 编号。当 N 为 0 时,全部输入结束,相应的结果不要 输出。 输出描述:
8、下列有关总线定时的叙述中,错误的是()。(点击查看答案>>>>>>>>) A、异步通信方式中,全互锁协议最慢 B、异步通信方式中,非互锁协议的可靠性最差 C、同步通信方式中,同步时钟信号可由各设备提供 D、半同步通信方式中,握手信号的采样由同步时钟控制
9、若磁盘转速为 7200 转/分,平均寻道时间为 8ms,每个磁道包含 1000 个扇 区,则访问一个扇区的平均延迟时间大约是()。(点击查看答案>>>>>>>>) A、8.1ms B、12.2ms C、16.3ms D、20.5ms
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
浙江大学计算机复试上机2005-2007(由林子整理)2005年浙江大学计算机学院考研复试上机试题及参考答案(1/5)第一题:A+B(10分) [结题]题目要求:读入两个小于100的正整数A和B,计算A+B。
需要注意的是:A和B的每一位数字由对应的英文单词给出。
输入格式:测试输入包含若干测试用例,每个测试用例占一行,格式为"A + B =",相邻两字符串有一个空格间隔。
当A和B同时为0时输入结束,相应的结果不要输出。
输出格式:对每个测试用例输出1行,即A+B的值。
输入样例:one + two =three four + five six =zero seven + eight nine =zero + zero =输出样例:39096#include <>#include <>#include <>#include <>int main(void){const char data[12][6] = {"zero", "one","two", "three", "four","five", "six", "seven", "eight", "nine", "+", "="};unsigned a, b; /* 转换后的表达式参数,如a+b(123+456) */unsigned i, j, k; /* 临时变量,作为下标*/ char str[100]; /* 输入字符串,足够大容量*/ char temp[6]; /* 临时字符串,用于检索数字,如"one"->'1' */char result[30]; /* 转换后的表达式参数,如"123+456=" */a =b = i = j = k = 0; /* 初始化变量 */memset(str, 0, sizeof(str));memset(temp, 0, sizeof(temp));memset(result, 0, sizeof(result));gets(str); /* 获取输入字符串,不能使用scanf,因为有空格 */for(i=0, k=0; i<strlen(str); ++i){for(j=0;!isspace(str[i])&&i<strlen(str);++i,++j) /* 提取一个单词 */temp[j] = str[i];temp[j] = 0; /* 字符串结束标记 */for(j=0; j<12; j++) /* 把这个单词转换为数字 */if(strcmp(temp, data[j]) == 0){if( j <= 9 ) result[k++] = j + '0';if( j == 10 ) result[k++] = '+';if( j == 11 ) result[k++] = '=';break; /* 找到匹配数字就不必再搜索了 */ }result[k] = 0; /* 字符串结束标记,result形式"123+456=" */sscanf(result,"%d+%d=",&a,&b); /* 用sscanf来获得a,b的值 */if( a==0 && b==0 ) break; /* A,B同时为零则退出程序 */else printf("%d\n", a + b); /* 打印输出 A + B 的数值 */}while(1);return 0;}2005年浙江大学计算机学院考研复试上机试题及参考答案(2/5)第二题:谁是开门关门的人?(10分)题目要求:每天第一个到机房的人要把门打开,最后一个离开的人要把门关好。
现有一堆杂乱的机房签到、签离记录,请根据记录找出当天开门和关门的人。
输入格式:测试输入的第一行给出记录的总天数N ( > 0 )。
下面列出了N天的记录。
每天的记录在第一行给出记录的条目数M ( > 0 ),下面是M 行,每行的格式为证件号码签到时间签离时间其中时间按“小时:分钟:秒钟”(各占2位)给出,证件号码是长度不超过15的字符串。
输出格式:对每一天的记录输出1行,即当天开门和关门人的证件号码,中间用1空格分隔。
注意:在裁判的标准测试输入中,所有记录保证完整,每个人的签到时间在签离时间之前,且没有多人同时签到或者签离的情况。
输入样例:31ME25321 00:00:00 23:59:592EE301218 08:05:35 20:56:35MA301134 12:35:45 21:40:423CS301111 15:30:28 17:00:10SC3021234 08:00:00 11:25:25CS301133 21:45:00 21:58:40输出样例:ME25321 ME25321EE301218 MA301134SC3021234 CS301133#include <>#include <>#include <>typedef struct{char id[16]; /* 证件号码长度不超过15位 */ char cometime[9]; /* 时间格式00:00:00 */ char leavetime[9]; /* 时间格式00:00:00 */ }Record;int main(){int N, M, i; /* 记录的总天数N,每天记录的条目数M */ Record *pTimeList;/* 记录该天出入人员的证件号码、进入时间、离开时间 */int first, last; /* 记录每天开门的人和关门的人 */ scanf("%d",& N); /* 读入记录的总天数 */while(N--){scanf("%d", & M); /* 读入该天的进出人员数 */pTimeList = (Record *)malloc(M*sizeof(Record));for(i=0,first=0,last=0; i<M; ++i){scanf("%s%s%s", pTimeList[i].id,pTimeList[i]etime, pTimeList[i].leavetime);if(i==0)continue;else{if( strcmp( pTimeList[first]etime,pTimeList[i]etime ) > 0 )first = i;if( strcmp( pTimeList[last].leavetime,pTimeList[i].leavetime) < 0)last = i;}} /* for i */printf("%s %s\n", pTimeList[first].id,pTimeList[last].id);free(pTimeList);} /* for N */}2005年浙江大学计算机学院考研复试上机试题及参考答案(3/5)第三题:分数统计(12分)题目要求:今天的上机考试虽然有实时的Ranklist,但上面的排名只是根据完成的题数排序,没有考虑每题的分值,所以并不是最后的排名。
给定录取分数线,请你写程序找出最后通过分数线的考生,并将他们的成绩按降序打印。
输入格式:测试输入包含若干场考试的信息。
每场考试信息的第1行给出考生人数N ( 0 < N < 1000 )、考题数M ( 0 < M < = 10)、分数线(正整数)G;第2行排序给出第1题至第M题的正整数分值;以下N行,每行给出一名考生的准考证号(长度不超过20的字符串)、该生解决的题目总数m、以及这m道题的题号(题目号由1到M)。
当读入的考生人数为0时,输入结束,该场考试不予处理。
输出格式:对每场考试,首先在第1行输出不低于分数线的考生人数n,随后n行按分数从高到低输出上线考生的考号与分数,其间用1空格分隔。
若有多名考生分数相同,则按他们考号的升序输出。
输入样例:4 5 2510 10 12 13 15CS004 3 5 1 3CS003 5 2 4 1 3 5CS002 2 1 2CS001 3 2 3 51 2 4010 30CS001 1 22 3 2010 10 10CS000000000000000001 0CS000000000000000002 2 1 2输出样例:3CS003 60CS001 37CS004 371CS000000000000000002 20#include <>#include <>#include <>typedef struct{char id[21]; /* 准考证号(<=20字符) */int score; /* 该考生总分*/}StuInfo;int main(){int N, M, G, n; /* 考生人数,题目数,分数线,上线考生数量 */int *pMarkList; /* 第1题至第M题的正整数分值*/StuInfo *pStuinfo; /* 考生信息 */int i,j,k,a,b,c,m; /* 临时变量 */StuInfo tmp; /* 用于排序 */while( scanf("%d", &N ) && N!=0 ) /* 读入考生人数N */{scanf("%d%d", &M, &G); /* 读入题目数量和分数线 */pMarkList = (int*)malloc(M*sizeof(int)); /* M道题目的分数 */pStuinfo = (StuInfo*)malloc(N*sizeof(StuInfo)); /* N个考生 */for(i=0; i<M; ++i) /* 读入M题每题分数*/scanf("%d", & (pMarkList[i]) );for(i=0, n=0; i<N; ++i) /* 读入N个考生信息,i用于计数N次,cnt用于计算上线考生记录 */{scanf("%s%d", & (pStuinfo[n].id), &m);/* 准考证号,解出的题目数量m */for(pStuinfo[n].score=0,j=0;j<m; ++j) /* 读入答出的m题的题号 */{scanf("%d", & a );/* 读入答对题的题号 */pStuinfo[n].score += pMarkList[ a-1 ]; /* 因为题号是从1开始的;计算该考生的总分 */}if(pStuinfo[n].score >= G) /* 如果考生上线则记录下来 */n++;/* 否则不予记录,便于排序 */}for(i=0; i<n-1; ++i) /* 输入完毕,对上线考生先按分数排序,降序 */{for(k=i, j=i+1; j<n; ++j)if(pStuinfo[j].score > pStuinfo[k].score)k = j;tmp = pStuinfo[k];pStuinfo[k] = pStuinfo[i];pStuinfo[i] = tmp;}for(i=0; i<n; i+=k) /* 相同总分考生再按照准考证号排序 */{/* 统计相同分数考生人数k */for(k=1,j=i+1; j<n; ++j){if(pStuinfo[i].score == pStuinfo[j].score)k++;elsebreak;}/* 下标i到i+k的考生分数相同,对这k个考生排序,升序 */for(a=i; a<=i+k-1; a++){for(c=a, b=a+1; b<=i+k; b++)if(strcmp(pStui nfo[c].id, pStuinfo[b].id) > 0)c = b;tmp = pStuinfo[a];pStuinfo[a] =pStuinfo[c];pStuinfo[c] = tmp;}}printf("%d\n",n); /* 排序完毕,按照要求输出,上线人数 */for(i=0; i<n; ++i) /* 和每个上线考生的准考证号和总分数 */printf("%s %d\n",pStuinfo[i].id ,pStuinfo[i].score);free(pMarkList);free(pStuinfo);}return 0;}2005年浙江大学计算机学院考研复试上机试题及参考答案(4/5)第四题:最大连续子序列(13分)题目要求:给定K个整数的序列{ N1, N2, ..., NK },其任意连续子序列可表示为{ Ni, Ni+1, ...,Nj },其中 1 <= i <= j <= K。