首届程序设计大赛题目及答案
编程中国第一届 程序设计大赛 试题

编程中国第一届程序设计大赛试题编程中国第一届程序设计大赛试题竞赛ID:____一、选择题(1)int a = 3; a++ + a++ 的值为A)6 B)7C)8 D)依赖于实现(2)下列哪一个数据类型的符号类型是不确定的A)char B)shortC)int D)long(3)-1 >> 2 的值为A)0 B)4C)6 D)依赖于实现(4)typedef struct{short a;}book; siozeof(book) 的值为A)2 B)4C)8 D)依赖于实现(5)char *p = “blueguy”; sizeof(p) 的值为A)7 B)8C)4 D)依赖于实现(6)下列哪一个c语言图形库是目前最优秀的图形库A)opengl B)easyXC)gdi D)curses(7)《opengl 编程指南》一书现已出版到第几版A)五B)六C)七D)八(8)下列哪一项不属于像素的颜色分量A)R B)GC)B D)E(9)下列哪一项是“帧率” 的英文缩写A)FPS B)LSBC)MSD D)LHS(10)bmp图片的一个像素占几个字节A)1 B)2C)3 D)4(11)下列哪一种遍历方式与树的递归定义无关A)层序遍历 B)前序遍历C)中序遍历 D)后序遍历(12)下列哪一种数据结构与广度优先搜索最为相关A)链表 B)栈C)队列 D)树(13)sin(30’)放大100倍的值为A)50 B)100C)1 D)70(14)下列哪一项工具可以用于格式化代码A)BeyondCompare B)UltraEditC)Astyle D)PcLint(15)下列排序算法中哪一种是最简单的A)冒泡排序 B)选择排序C)插入排序 D)希尔排序(16)int a = 7; a & 3 的值为A)1 B)3C)5 D)7(17)下列哪一项不属于预处理器命令A)#if B)#elseC)#endif D)if(18)Vs2005中,编译选项 /RTCu 的作用是A)未初始化变量使用检查 B)缓冲区溢出检查C)堆栈检查 D)数据转换检查(19)下列哪一个标识符不能用于定义常量A)int B)constC)enum D)#define(20)设fp 已定义,执行语句fp = fopen(“file”, “w”); 后,以下针对文本文件file操作叙述的选项中正确的是A)既能读又能写 B)只能写不能读C)只能读不能写 D)既不能读又不能写二、填空题(1)现将bmp图像的像素值按顺序读入char a[]中,假设bmp图片的左上角为(0, 0)点,那么,像素(x, y)对应a中的位置为____。
程序设计竞赛试题和题解

程序设计竞赛试题和题解付浩fuch@Contents完全平方数 (2)拉丁方阵 (3)取石子游戏 (5)乡村医院 (7)未知星球 (9)无聊的游戏 (10)最短路径 (12)完全平方数描述一个非负整数n是完全平方数当且仅当存在非负整数m,使得n=m2据说完全平方数具有某种神奇的力量,谁知道呢。
聪明的你一定想到了,这道题的任务就是编写一个程序,判断给定的n是否是完全平方数。
输入格式输入包含多组数据。
每组数据占一行,包含一个非负整数n,n不超过109输入以n=-1结束输出格式对每组输入数据输出一行,如果n是完全平方数则输出”Yes”,否则输出”No”输入样例1234-1输出样例YesYesNoNoYes解答一般的语言都有开平方运算吧?拉丁方阵描述拉丁方阵是一种n×n的方阵,方阵中恰有n种不同的元素,每种元素恰有n个,并且每种元素在一行和一列中恰好出现一次。
著名数学家和物理学家欧拉使用拉丁字母来作为拉丁方阵里元素的符号,拉丁方阵因此而得名。
例如下图是一个3×3的拉丁方阵:如果一个拉丁方阵的第一行和第一列按照元素的先后顺序来排列,那么这称为拉丁方阵的标准型,例如下图就是一个3x3的拉丁方阵标准型,第一行和第一列都是”1 2 3”。
你的任务是,编写一个程序读入一个方阵,判断其是否为拉丁方阵;进一步地,判断是否为标准型。
输入格式输入包含多组数据。
每组数据第一行为正整数n,表示方阵的大小。
其后n行,每行有n个1到n之间的整数,整数之间恰有一个空格,表示方阵的内容。
输入保证1≤n≤100输入以n=0结束,不要处理这个数据。
输出格式每组数据对应于一行输出。
如果输入是拉丁方阵,但不是标准型则输出1;如果输入是标准型则输出2;如果输入不是拉丁方阵则输出0输入样例21 12 233 2 12 1 31 3 231 2 33 2 12 1 254 35 2 15 4 1 3 21 52 4 32 13 5 43 24 15 31 2 32 3 13 1 2输出样例112解答按定义做判断。
湖南工学院首届程序设计大赛试题

湖南工学院首届程序设计大赛试题时间:5月18日 9:00---12:00地点:2517题目一输入2个正整数(位数不超过100位),计算它们的差并输出;示例输入:99999999999999999999999999999998888888888888888888888888888888输出:1111111111111111111111111111111题目二也许是因为有10 个手指的原因,所以我们把0~9 十个数字组合起来表达任意的数值,但这并不是唯一可能的记数法。
在某个外星球居住着一种智慧生物,他们的手跟我们的手构造不同,他们的记数法也很奇特。
他们用三个记号’0’,’1’,’-’的组合来表达数值,这三个记号分别对应数值0,1,-1。
在他们的数值系统中,每个数位是右边相邻数位的3 倍。
因此数’10-’表示数值8(因为8=1×9+0×3 +-1×1),数’-1’表示数值-2(因为-2= -1×3+1×1)。
编写程序,读入一组-231 至231-1 之间的数值,输出对应的外星球数值表示。
输入:每行一个10 进制数值输出:每行一个与输入文件对应的外星球数值表示示例输入:102-1742-2147483648输出:1011--1011---0-10110100011---1-1--1题目三输入30个数到一个5行6列数组,经排序后该数组各元素值按列从小到大排列,并显示该2维数组;示例输入:1 3 20 11 13 102 6 21 12 18 195 4 27 14 15 167 9 17 22 23 248 0 25 26 28 29示例输出:0 5 10 15 20 251 6 11 16 21 262 7 12 17 22 273 8 13 18 23 284 9 14 19 24 29题目四轮回矩阵(输入输出文件名:rect.in /rect.out)阿长最近迷上了一种矩阵,他认为通过分析这种图形可以参悟人的生死轮回。
C语言程序设计大赛题目和答案1

//C语言程序设计题目和答案大赛/*-------------------第一题某人到商店购物,身上有钱m元,商店里有商品n件,如果只能买1件或2件商品,且想一次性把钱花完,编程求是否可行?输入数据:第一行输入两个整数n和m(1≤n≤30000,1≤m≤10000),下面n行中每一行都是一个整数a,表示商店中商品的价格,1≤a≤10000。
输出数据:如果可以恰好用m元钱买到1件或者是2件东西,则第一行输出YES,随后的一行或两行输出所买商品的价格;否则输出NO。
输入样例:5 201371318输出样例:YES713-----------------------*/#include <stdio.h>#include <malloc.h>void main(){int m, n;int *a;int i,j;scanf("%d%d",&n,&m); //输入商品数及钱的多少a=(int*)malloc(n*sizeof(int));for(i=0;i<n;i++) scanf("%d",a+i); //输入每件商品的价格for(i=0;i<n;i++)if(a[i]==m) {printf("%s\n%d\n","YES",a[i]); break;}elsefor(j=i+1;j<n;j++)if(a[i]+a[j]==m) {printf("%s\n%d\n%d\n","YES",a[i],a[j]); return;} if (i==n) printf("\nNO\n");}/*----------------------第二题写出一个程序,接受一个以N/D的形式输入的分数,其中N为分子,D为分母,输出它的小数形式。
编程初赛考试题及答案

编程初赛考试题及答案一、选择题(每题2分,共10题,满分20分)1. 下列哪个选项是Python语言的标识符?A. 2variableB. variable2C. variable-2D. variable2_答案:B2. 在HTML中,用于定义最重要的标题的标签是?A. `<h1>`B. `<h6>`C. `<p>`D. `<div>`答案:A3. 以下哪个选项不是JavaScript的数据类型?A. NumberB. StringC. UndefinedD. List答案:D4. 在CSS中,哪个属性用于设置文本的颜色?A. `color`B. `background-color`C. `font-size`D. `text-align`答案:A5. SQL语句中,用于查询数据的关键字是?A. SELECTB. INSERTC. UPDATED. DELETE答案:A二、填空题(每题3分,共5题,满分15分)1. 在Python中,用于定义函数的关键字是____。
答案:def2. HTML文档的结构以____标签开始,以____标签结束。
答案:<html>、</html>3. JavaScript中,用于获取元素的DOM方法为____。
答案:getElementById4. CSS选择器中,用于选择类名为"example"的所有元素的符号是____。
答案:.example5. SQL中,用于添加数据的语句是____。
答案:INSERT INTO三、简答题(每题5分,共2题,满分10分)1. 请简述什么是算法,并给出一个简单的例子。
答案:算法是解决问题的一系列定义清晰的计算步骤。
例如,冒泡排序算法是一种简单的排序算法,它通过重复遍历待排序的数列,比较每对相邻元素,如果他们的顺序错误就把他们交换过来,遍历数列的工作是重复进行直到没有再需要交换,也就是说该数列已经排序完成。
首届中创杯程序设计大赛试题

首届中创杯程序设计大赛试题前5题每题10分,后3题每题20分一.进制转换(10分)问题描述:请你编写程序,将给定的十进制数转化成相应的十六进制数并输出。
请你编写程序,将给定的十进制数转化成相应的十六进制数并输出。
输入格式:输入只有一行一个整数N (1 < N < 100000)。
输出格式:输出只有一行,为一个与N 对应的十六进制数K 。
样例输入:26 样例输出:1A 二.递归函数(10分) 有这样一个函数:0,1(,)(0.73,)(,8.4)11(/2,1)(1,/3)1xx y x y x y F x y F x y F x y x y x y F x y F x y x yy x =ìï¹ï=í-+-+++>³ïï-+-++>³î且至少有一个小于 键盘输入实数a 和b(0 < a, b < 100),计算该函数当x=a, y=b 的值并输出到屏幕。
输入值最多有四位小数,输出时四舍五入保留两位小数。
小数,输出时四舍五入保留两位小数。
样例:输入输出9.2 5.6 36.47键盘输入两个两位正整数a ,b ( 11 < = a,b < = 99,且a 和b 都不包含数字’0’ ),在屏幕上输出a 与b 相乘的竖式。
注意尽量按照样例的格式进行输出。
相乘的竖式。
注意尽量按照样例的格式进行输出。
样例:输入输出25 1225 * 12 ------50 25 ------300 三.数字金字塔(10分)问题描述:数字金字塔是由1到N 的数字构成的一个类似金字塔形状的数阵。
其中,第一层由1个数字1构成,第二层由2个数字2构成,第三层由3个数字3构成(每层均比上一层多1个数字,个数字,且且每一层的数字之间都有一个空格格开)……。
例如,当N=4时,一个4层的数字金字塔如下:层的数字金字塔如下:OOO1OO2O2 O3O3O34O4O4O4为了方便描述,上图中的“O”表示空格。
大学生程序设计竞赛试题(正式赛)

中原工学院第一届大学生程序设计竞赛正式比赛试题主办:中原工学院教务处学生处校团委计算机学院承办:中原工学院计算机学院地点:计算机学院实验中心406实验室时间:2010年4月11日【试题一】兔子【题目描述】兔子具有很强的繁殖能力。
一对成年兔子每个月可以繁殖一对小兔子,而一对小兔子经过m个月之后,就会长成一对成年兔子。
通过分析,我们可以看出:若m=2的时候,每个月兔子的对数构成了一个Fibonacci数列。
但是,若m<>2,这个问题看起来就不那么简单了。
你的任务是计算:假定初始只有一对兔子,那么,经过d个月之后,共有多少对兔子?可以假定,在此阶段没有任何兔子死亡。
【输入】输入包括多组测试数据。
每组测试数据的一行中包括2个整数m(1<=m<=10),d(1<=d<=30)。
当测试数据遇到一行中有两个0时,即m=d=0,测试数据结束。
【输出】针对每组测试数据,在每一行输出经过d个月后共有多少对兔子。
【输入样例】2 33 50 0【输出样例】59【试题二】网页浏览器【题目描述】Mozilla Firefox是一个自由的,开放源码的网页浏览器,适用于Windows, Linux 和MacOS X等平台。
Firefox火狐校园大使是Mozilla开源社区项目的一部分,针对在校的高年级本科生和研究生以及众多技术爱好者,在校园中推广开源项目和开放技术,让更多的开发人员受益于Mozilla的开放技术和免费资源。
你很荣幸得到了这样一个机会,为Firefox编写一个重要的导航模块。
正如上图所示,导航模块要接受用户的后退、前进、进入用户输入的网址以及清空浏览记录等操作。
【输入】为了简化问题,用户所有的操作都以字符的形式从标准输入读入。
每一行描述一个操作,各操作的格式和功能如下所示:浏览器启动时默认进入中原工学院的主页” .cn”【输出】对于每一个需要输出网址的操作,输出对应的网址。
每个网址恰好占一行,不要有多余的字符(包括空格和换行)。
第七届计算机技能大赛——首届程序设计竞赛预赛试题.

第七届计算机技能大赛——首届程序设计竞赛预赛试题.第七届计算机技能大赛——首届程序设计竞赛预赛试题(C\C++语言组考试时间:90分钟)考生姓名队名得分(全部试题答案写在答题纸上,答在试卷上一律无效)一、单项选择题(在每小题的备选答案中,选出一个正确的答案。
每小题2分,共26分)1.与十进制数23的值相等的二进制数是()。
A.10110 B. 11011 C. 11011 D. 10111 E. 100112.设有:int c1=1,c2=2,c3; 则执行c3=c1/c2后,c3的值是()A. 0B. 1/2C. 0.5D. 13.以下断电之后仍能保存数据的是()。
A. 硬盘B. 寄存器C. 显存D. 内存E. 高速缓存4.已知A的ASCII码为十进制65,且c2为字符型,则执行语句c2='A'+'6'-'3';后,c2存放的值为()A. D B .68 C.不确定的值 D.C5.一位艺术史学家有20000 幅真彩色图像,每幅图像约占3M空间。
如果将这些图像以位图形式保存在CD 光盘上(一张CD 光盘的容量按600M 计算),大约需要()张CD光盘。
A. 1B. 10C. 100D. 1000E. 100006.文件包含的含义是指()A.定义常量B.定义变量C.引入已定义的函数D.引入标准库函数7.下列关于高级语言的说法错误的是()。
A. Fortran是历史上的第一个面向科学计算的高级语言B. Pascal和C都是编译执行的高级语言C. C++是历史上的第一个支持面向对象的语言D. 编译器将高级语言程序转变为目标代码E. 高级语言程序比汇编语言程序更容易从一种计算机移植到另一种计算机上8.下面关于"F"的说法正确的是()A.它代表一个字符常量B.它代表一个字符串常量C.它代表一个字符FD.它代表一个变量9.在C语言中,char类数据在内存中是以()形式存储的A.原码B.反码C.补码D.ASCII码10.下列哪个软件属于操作系统软件()A. Microsoft WordB. 金山词霸C. FoxmailD. WinRARE. Red Hat Linux11.在下列选项中,没有构成死循环的程序结构是()A. int i =100;B. for (;;;)while(1){ i=i%3;if (i>100) break;}C. int k=1000;D. int s=36;do {k;} while(k>1000); while (s);--s;12.设有int i;则表达式(i=1,i=0)?i++||++i:++i的值为( )A.1B.2C.3D.1013.美籍匈牙利数学家冯·诺依曼对计算机科学发展所做出的贡献是:()A. 提出理想计算机数学模型,成为计算机科学理论基础B. 是世界上第一个编写计算机程序的人C. 提出存储程序工作原理,并设计出第一台具有存储程序功能的计算机EDV ACD. 采用集成电路作为计算机的主要功能部件二、程序填空题(每空3分,共30分)1.程序功能描述:给出一个正整数,判断这个数是否是质数。
c语言程序设计比赛试题及答案

c语言程序设计比赛试题及答案一、选择题(每题2分,共20分)1. 下列哪个选项是C语言中的合法整数常量?A. 0x1AB. 01AC. 0b1010D. 1.23答案:A2. C语言中,哪个关键字用于定义一个函数?A. structB. intC. voidD. return答案:B3. 下列哪个选项是C语言中正确的注释方式?A. // 这是注释B. /* 这是注释 */C. //* 这是注释D. /* 这是注释答案:B4. C语言中,哪个运算符用于求两个数的和?A. +B. -C. *D. /答案:A5. 在C语言中,哪个关键字用于定义一个结构体?A. structB. unionC. enumD. typedef答案:A6. C语言中,哪个关键字用于定义一个枚举类型?A. structB. unionC. enumD. typedef答案:C7. 下列哪个选项是C语言中合法的变量名?A. 2variableB. variable2C. _variableD. variable$2答案:B8. 在C语言中,哪个关键字用于定义一个指针?A. intB. floatC. charD. *答案:D9. C语言中,哪个函数用于将字符串复制到另一个字符串?A. strcpyB. strcatC. strcmpD. strlen答案:A10. 在C语言中,哪个函数用于计算字符串的长度?A. strcpyB. strcatC. strcmpD. strlen答案:D二、填空题(每题2分,共20分)1. C语言中,用于定义一个整型数组的关键字是________。
答案:int2. C语言中,用于定义一个字符型数组的关键字是________。
答案:char3. C语言中,用于定义一个浮点型数组的关键字是________。
答案:float4. C语言中,用于定义一个双精度浮点型数组的关键字是________。
答案:double5. C语言中,用于定义一个字符串的关键字是________。
程序设计试题及答案

程序设计试题及答案一、选择题(每题2分,共20分)1. 在C语言中,以下哪个关键字用于定义一个函数?A. intB. voidC. returnD. function答案:A2. 下列哪个选项是合法的C语言变量名?A. 2variableB. variable-nameC. variable#nameD. variable_name答案:D3. 在C语言中,以下哪个语句用于结束一个循环?A. continueB. breakC. exitD. return答案:B4. 以下哪个选项是C语言中的条件语句?A. ifB. switchC. forD. while答案:A5. 在C语言中,数组的索引是从哪个数字开始的?A. 0B. 1C. -1D. 随机数答案:A6. 以下哪个是C语言中的标准输入输出库?A. <iostream>B. <stdio.h>C. <iostream.h>D. <stdio>答案:B7. 在C语言中,以下哪个函数用于计算两个数的和?A. pow()B. sqrt()C. abs()D. sum()答案:D(注意:sum()不是C语言标准库函数,这里假设为自定义函数)8. 以下哪个选项是C语言中的循环结构?A. if-elseB. switch-caseC. for, while, do-whileD. try-catch答案:C9. 在C语言中,以下哪个关键字用于定义一个结构体?A. classB. structC. unionD. enum答案:B10. 下列哪个选项是C语言中的位操作符?A. &&B. ||C. &D. ++答案:C二、填空题(每题2分,共20分)11. 在C语言中,使用________关键字可以定义一个指针。
答案:int* 或者 *(具体类型根据上下文)12. 一个C语言程序的执行从________函数开始。
C语言程序设计大赛题目和答案

C语言程序设计大赛题目和答案在C语言程序设计领域,程序设计大赛是一种常见的形式,它旨在考察参赛者的编程能力和解决问题的能力。
本文将介绍一些常见的C 语言程序设计大赛题目和对应的答案,帮助读者了解这些题目的难度和解题思路。
一、题目一:计算数列和题目描述:给定一个正整数n,计算1到n的所有整数的和。
解答思路:可以使用循环结构来解决该问题。
初始化一个累加器sum,然后通过循环依次将1到n的数累加到sum中,最终得到结果。
```c#include <stdio.h>int main() {int n;int sum = 0;printf("请输入一个正整数n:");scanf("%d", &n);for (int i = 1; i <= n; i++) {sum += i;}printf("1到%d的和为:%d\n", n, sum);return 0;}```二、题目二:判断素数题目描述:给定一个正整数n,判断其是否为素数(只能被1和自身整除的数)。
解答思路:可以使用循环结构和条件判断来解决该问题。
通过循环从2到n-1依次判断n是否能被这些数整除,如果能,则n不是素数;如果循环结束后仍然没有找到能整除的数,则n是素数。
```c#include <stdio.h>#include <stdbool.h>bool isPrime(int n) {if (n <= 1) {return false;}for (int i = 2; i < n; i++) {if (n % i == 0) {return false;}}return true;}int main() {int n;printf("请输入一个正整数n:");scanf("%d", &n);if (isPrime(n)) {printf("%d是素数\n", n);} else {printf("%d不是素数\n", n);}return 0;}```三、题目三:矩阵乘法题目描述:给定两个矩阵A和B,计算它们的乘积矩阵C。
ACM程序大赛选拔初赛试题 - 参考答案

a[n]=n+1; int x=0; while(n>=1) {
if(a[i]!=0) {
if(x%2==0) { if(n==2) printf("\n"); printf("%d ",a[i]); n--; a[i]=0; } x++; } if(i+1>=size) i=0; else i++; } }
4、解方程 难度系数:★★☆☆☆
(注意此题只供 10 级的同学,08,09 级的同学请做第三题) 题意:形如 ax2+bx+c=d 的方程。其中 a,c,d 均为整数,b 为正整数。请你用计算机求出对 应的 x 的值(只考虑实数根)。
输入:依次输入 a,b,c,d 的值。注意:只要输入一组数据。用空格隔开。
char temp,str[10]; scanf("%s",str);
for(int i=0;i<9;i++) for(int j=i+1;j<10;j++) if(str[i]>str[j]) { temp=str[i]; str[i]=str[j]; str[j]=temp; }
cout<<str<<endl; }
输入:依次输入函数的四个系数中的 a,b,c,d 的值。用空格隔开。
输出:如果有极值点则全部输出,结果保留两位小数,格式为“(x1=#,y1=#) (x2=#,y2=#)”,如果没有则输入“no answer。
小学生计算机程序设计竞赛试卷及参考答案

小学生计算机程序设计竞赛试卷及参考答案1、下列表达式的值为FALSE的是()。
A. Not(‘90’’100’)B.Round((Abs(-10.5))) 10C. Odd(True(98.49))D.Ord(Chr(Pred(8))) =72、判断变量ch的值是否为大写字母,下列表达式正确的是()。
A. ch =’A’and ch =’Z’B.’A’=ch =’Z’C.(ch =A)and(ch =Z)D. not(ch ’A’)or(ch ’Z’)3、表达式Chr(Ord(‘a’)+5))的值是()。
A.’f’B.‘E’C.102D.1014、与十进制数2014等值的二进制数是()。
A.11111011110B.11110011110C.10111111110D.111111110105、[x]补码=10011101,其原码为()。
A.11001111B.11100100C.11100011D.011001016、十进算术表达式:5*512+7*64+4*8+7的运算结果,用二进制表示为()。
A. 101111100111B.111111100101C. 111110100101D.1111110110117、(2014)16 + (924)10的结果是()。
A. (9036)10B. (23B0)16C. (9130)10D. (100011000110)2二、计算下列函数(1*15)1、Sqr(7)的值为()。
2、Round(19.6)的值为( )。
3、Round(14.4)的值为( )。
4、int(-5.7)的值为( )。
5、Abs(-4.1)的值为( )。
6、-37 mod 6的值为( )。
7、’A’’a’的值为()。
8、odd(25)的值( )。
9、Not(17-5 13)的值为( )。
10、(11 10)and(7 =7)的值为( )。
11、Round(-11.1)的值为( )。
程序设计大赛试题及答案

试题1、数学黑洞(程序文件名)【问题描述】任给一个4位正整数,其各位数位上的数字不全相同,将数字重新组合成一个最大的数与最小的数相减,重复这个过程,最多7步,必得6174。
对任给的4位正整数(各位数位上的数字不全相同),编程输出掉进黑洞的步数。
【输入】一行,一个4位正整数n(1000< n<9999)【输出】掉进黑洞的步数输入1234输出32、进制转换(程序文件名)【问题描述】任给一个十进制整数n,及正整数m(m<=16且m≠10), 将n转换成m进制并输出。
【输入】一行,两个整数n,m(0 ≤ n ≤ 500000,2 ≤ m ≤ 16,且m≠10),中间用一个空格隔开,其中n 表示十进制数。
【输出】转换后的数【输入输出样例】输入255 8输出3773、分数线划定(程序文件名)【问题描述】公务员选拔工作正在 A 市如火如荼的进行。
为了选拔优秀人才,A 市对所有报名的选手进行了笔试,笔试分数达到面试分数线的选手方可进入面试。
面试分数线根据计划录取人数的150%划定,即如果计划录取m名公务员,则面试分数线为排名第m*150%(向下取整)名的选手的分数,而最终进入面试的选手为笔试成绩不低于面试分数线的所有选手。
现在就请你编写程序划定面试分数线,并输出所有进入面试的选手的报名号和笔试成绩。
【输入】第一行,两个整数n,m(5 ≤ n ≤ 5000,3 ≤ m ≤ n),中间用一个空格隔开,其中n 表示报名参加笔试的选手总数,m 表示计划录取的人数。
输入数据保证m*150%向下取整后小于等于n。
第二行到第 n+1 行,每行包括两个整数,中间用一个空格隔开,分别是选手的报名号k(1000 ≤ k ≤ 9999)和该选手的笔试成绩s(1 ≤ s ≤ 100)。
数据保证选手的报名号各不相同。
【输出】第一行,有两个整数,用一个空格隔开,第一个整数表示面试分数线;第二个整数为进入面试的选手的实际人数。
c语言程序设计大赛初赛试题及答案

c语言程序设计大赛初赛试题及答案一、选择题(每题2分,共10分)1. 下列哪个选项是C语言中的关键字?A. intB. floatC. stringD. array答案:A2. C语言中,用于定义一个整型变量的关键字是?A. intB. charC. floatD. double答案:A3. 下列哪个选项不是C语言的标准输入输出函数?A. printfB. scanfC. coutD. getchar答案:C4. 在C语言中,下面哪个选项是正确的字符串定义?A. char str[] = "Hello";B. char str[] = {"Hello"};C. char str[] = 'Hello';D. char str[] = "Hello";答案:A5. 下列哪个选项是C语言中正确的注释方式?A. // This is a commentB. /* This is a comment */C. //* This is a commentD. /* This is a comment */答案:B二、填空题(每题3分,共15分)1. 在C语言中,定义一个整型数组可以使用关键字_________。
答案:int2. C语言中,_________函数用于输出字符串。
答案:printf3. C语言中,_________函数用于从标准输入读取一个字符。
答案:getchar4. C语言中,_________关键字用于定义一个函数。
答案:void5. C语言中,_________关键字用于定义一个结构体。
答案:struct三、编程题(每题10分,共20分)1. 编写一个函数,计算并返回两个整数的和。
```cint add(int a, int b) {return a + b;}```答案:```cint add(int a, int b) {return a + b;}```2. 编写一个程序,读取用户输入的两个整数,然后输出它们的乘积。
华南理工大学第一届程序设计竞赛比赛试题

华南理工大学第一届程序设计竞赛比赛试题华南理工大学首届大学生程序设计竞赛SCUTCPC试题Problem AIP AddressProblem descriptionSuppose you are reading byte stream s from any device, representing IP addresses. Your task is to convert a 32 characters long sequence of '1's and '0's (bits) to a dotted decim al format.A dotted decim al format for an IP address is form by grouping 8 bits at a tim e and converting the binary representation to decim al representation. Any 8 bits is a valid part of an IP address. To convert binary numbers to decim al numbers rem ember that both are positional numerical system s, where the first 8 positions of the binary system s are:2726252423222120128 64 32 16 8 4 2 1InputYou should read input data from the file of “ipaddress.in”.The input will have a number N (1<=N<=9) in its first line representing the number of stream s to convert. N lines will follow.OutputOutput your result to the standard output device.The output must have N lines with a doted decim al IP address. A dotted decim al IP address is formed by grouping 8 bit at the tim e and converting the binary representation todecim al representation.Sample Input400000000000000000000000000000000 00000011100000001111111111111111 11001011100001001110010110000000 01010000000100000000000000000001Sample Output0.0.0.03.128.255.255203.132.229.12880.16.0.1Problem BThe Greatest Common Divisor inAncient RomeProblem descriptionYou m ust have retrieved the GCD (Greatest Common Divisor) of two positive integers before. Do you want to have a try, to do that in Ancient Rom e Times?The Ancient Rom an, who lived hundreds of years ago, used a kind of symbols called “Roman numerals” for arithm etic.The following are 7 basic Rom an num erals:These 7 sym bols form all the other numbers. All the numbers are written from left to right. Usually, their values equal to the sum of the basic num erals. For example, seventeen can be represented by:X + V + I + I = XVII10 + 5 + 1 + 1 = 17But when the sam e Roman numerals appear continuously more than 4 tim es, they must be simplified by using the Subtraction Law. For example, “IX” replaces “VIIII” representing 9, and “CD” represents 400 instead of “CCCC”.Roman numerals are easy for Additions and Subtractions, but difficult for multiplication and division. That is the reason why Roman numerals are seldom used today.Now, we will have a try to calculate the GCD of the Rom an Numerals. All the numbers must be in the form of Roman Numerals. And the Subtraction Law is also required.InputYou should read input data from the file of “roman.in”.The input file consists of n lines (0 < n < 1000). Each line consists of two Roman Numerals, a and b, separate by a space.(0 < a < 4000, 0 < b < 4000)Process to End Of File.OutputOutput your result to the standard output device.Print the GCD in the form of Roman Numerals, in separate linesSample InputXXIV XVISample InputVIIIBangla NumbersProblem descriptionBangla numbers normally use 'kuti'(10000000), 'lakh'(100000), 'hajar' (1000), 'shata' (100) while expanding and converting to text. You are going to write a program to convert a given number to text with them.InputYou should read input data from the file of “bangla.in”.The input file may contain several test cases. Each case will contain a non-negative number <= 999999999999999.OutputOutput your result to the standard output device.For each case of input, you have to output a line starting with the case num ber with four digits adjust m ent followed by the converted text.Sample Input2376445897458973958Sample Output1. 23 hajar 7 shata 642. 45 lakh 89 hajar 7 shata 45 kuti 89 lakh 73 hajar 9 shata 58Output format exampleThe NetProblem descriptionTaking into account the present interest in the Internet, a sm art information routing becom es a must. This job is done by routers situated in the nodes of the network. Each router has its own list of routers which are visible for him (so called ``routing table"). It is obvious that the inform ation should be directed in the way which minimizes number of routers it has to pass (so called “hop count").Your task is to find an optim al route (m inimal hop count) for the given network form the source of the inform ation to its destination.InputYou should read input data from the file of “net.in”.First line contains number of routers in the network (n). Nextn lines contain description of the network. Each line contains router ID, followed by a hyphen and comma separated list of ID s of visible routers. The list is sorted in ascending order. Next line contains a number of routes (m) you should determine. The consecutive m lines contain starting and ending routers for the route separated by a single space. Input data m ay contain descriptions of many networks.OutputOutput your result to the standard output device.For each network you should output a line with 5 hyp hens and then, for each route, a list of routers passed by information sent from starting to destination routers.In case passing of information is impossible (no connection exists) you should output a string ``connection im possible". In case of m ultiple routes with the sam e`hop count' the one with lower ID s should be outputted (in case of route form router 1 to 2 as 1 3 2 and 1 4 2 the 1 3 2 should be outputted).Assumptions: A number of routers is not greater than 300 and there are at least 2 routers in the network. Each routers ``sees" no more than 50 routers.Sample Input61-2,3,42-1,33-1,2,5,64-1,55-3,4,66-3,561 61 52 42 53 62 1101-22-3-44-85-16-27-3,98-109-5,6,710-839 105 99 2Sample Output -----1 3 61 3 52 1 42 3 53 62 1-----9 7 3 4 8 10connection impossible9 6 2Problem EDelta-waveProblem descriptionOn the triangular field shown on the picture, sm alltriangles are numbered from1 to ∞(infinity). Travellerwants to go from triangle M to triangle N. Traveller canmove only through the sides of triangles, not vertices. The number of sides he crosses is called the path length.You are to determine the shortest path from M to N.InputYou should read input data from the file of “wave.in”.The first line is the number of test cases, followed by a blank line. Each test case of the input contains integers M and N (1<=M,N<=1000000000), separated by som e spaces. Each test case will be separated by a single line.OutputOutput your result to the standard output device.For each test case, your programm should print the length of the shortest path from M to N. Print a blank line between the outputs for two consecutive test cases.Sample Input16 12Sample Output3Problem FBest SequenceProblem descriptionThe twenty-first century is a biology-technology developing century. One of the most attractive and challenging tasks is on the gene project, especially on gene sorting program. Recently we know that a gene is made of DNA. The nucleotide bases from which DNA is built are A(adenine), C(cytosine), G(guanine), and T(thym ine). Given several segm ents of a gene, you are asked to m ake a shortest sequence from them. The sequence should use all the segm ents, and you cannot flip any of the segm ents.For example, given 'TCGG', 'GCAG', 'CCGC', 'GATC' and 'ATCG', you can slide the segm ents in the following way and get a sequence of length 11. It is the shortest sequence (but m ay be not the only one).InputYou should read input data from the file of “best.in”.The first line is an integer T (1 <= T <= 20), which shows the number of the cases. Then T test cases follow. The first line of every test case contains an integer N (1 <= N <= 10), which represents the number of segments. The following N lines express N segm ents, respectively. Assum ing that the length of any segm ent is between 1 and 20.OutputOutput your result to the standard output device.For each test case, print a line containing the length of the shortest sequence that can be m ade from these segm ents.Sample Input15TCGGGCAGCCGCGATCATCGSample Output11Problem GDivisibilityProblem descriptionConsider an arbitrary sequence of integers. One can place + or - operators between integers in the sequence, thus deriving different arithm etical expressions that evaluate to different values. Let us, for example, take the sequence: 17, 5, -21, 15. There are eight possible expressions:17 + 5 + -21 + 15 = 1617 + 5 + -21 - 15 = -1417 + 5 - -21 + 15 = 5817 + 5 - -21 - 15 = 2817 - 5 + -21 + 15 = 617 - 5 + -21 - 15 = -2417 - 5 - -21 + 15 = 4817 - 5 - -21 - 15 = 18We call the sequence of integers divisible by K if + or - operators can be placed between integers in the sequence in such way that resulting value is divisible by K. In the above example, the sequence is divisible by 7 (17+5+-21-15=-14) but is not divisible by 5.You are to write a program that will determine divisibility of sequence of integers. InputYou shoul d read input data from the file of “divisibility.in”.The first line of the input file contains a integer M indicatingthe number of cases to be analyzed. Then M couples of lines follow.For each one of this couples, the first line contains two integers, N and K(1 <= N <= 10000, 2 <= K <= 100) separated by a space. The second linecontains a sequence of N integers separated by spaces. Each integer is not greater than 10000 by it's absolute value.OutputOutput your result to the standard output device.For each case in the input file, write to the output file the word "Divisible" if given sequence of integers is divisible by K or "Not divisible" if it's not.Sample input24 717 5 -21 154 517 5 -21 15Sample OutputDivisibleNot divisibleProblem HHow Many Calls?Problem descriptionThe fibonacci number is defined by the following recurrence: fib(0) = 0fib(1) = 1fib(n) = fib(n-1)+fib(n-2)But we're not interested in the fibonacci num bers here. Wewould like to know how many calls does it take to evaluate the n th fibonacci num ber if we follow the given recurrence. Since the num bers are going to be quite large, we'd like to m ake the job a bit easy for you. We'd only need the last digit of the num ber of calls, when this number is represented in base b.InputYou shoul d read input data from the file of “calls.in”.Input consists of several test cases. For each test you'd be given two integers n (0 <= n <= 2147483647), b (0 < b <= 10000). Input is terminated by a test case where n=0 and b=0, you must not process this test case.OutputOutput your result to the standard output device.For each test case, print the test case number first. Then print n, b and the last digit (in base b) of the number of calls. There would be a single space in between the two numbers of a line. Note that the last digit has to be represented in decimal number system.Sample Input0 1001 1002 1003 10010 100 0Sample OutputCase 1: 0 100 1Case 2: 1 100 1Case 3: 2 100 3Case 4: 3 100 5Case 5: 10 10 7。
编程竞赛考试题库及答案

编程竞赛考试题库及答案1. 编程竞赛考试题库及答案1.1 题目一:字符串反转编写一个函数,输入一个字符串,输出该字符串的反转结果。
答案:```pythondef reverse_string(s):return s[::-1]```1.2 题目二:找出数组中的最大值给定一个整数数组,请找出数组中的最大值并返回。
答案:```pythondef find_max_value(arr):return max(arr)```1.3 题目三:计算阶乘编写一个函数,输入一个非负整数n,返回n的阶乘。
答案:```pythondef factorial(n):if n == 0:else:return n * factorial(n-1)```1.4 题目四:判断回文数编写一个函数,判断输入的整数是否为回文数。
答案:```pythondef is_palindrome(x):str_x = str(x)return str_x == str_x[::-1]```1.5 题目五:合并两个有序数组给定两个有序整数数组nums1和nums2,其中nums1的长度为m,nums2的长度为n,请你将nums2合并到nums1中,使合并后的数组仍然有序。
答案:```pythondef merge(nums1, m, nums2, n):i, j = m - 1, n - 1index = m + n - 1while i >= 0 and j >= 0:if nums1[i] > nums2[j]:nums1[index] = nums1[i]i -= 1else:nums1[index] = nums2[j]index -= 1nums1[:index+1] = nums2[j+1:]```1.6 题目六:寻找两个有序数组的中位数给定两个大小分别为m和n的有序数组nums1和nums2,请找出这两个数组的中位数。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
首届程序设计大赛题目及答案程序设计大赛题目1. 硬币兑换:用一元人民币兑换一分、二分和五分的硬币,编程求出所有兑换方法,并打印每种情况下各面值硬币需几枚?(10分)2. 旅馆里有一百个房间,从1到100编了号。
第一个服务员把所有的房间门都打开了,第二个服务员把所有编号是2的倍数的房间“相反处理”,第三个服务员把所有编号是3的倍数的房间作“相反处理”,……,以后每个服务员都是如此。
问第100个服务员来过后,哪几扇门是打开的。
(所谓“相反处理”是:原来开着的门关上,原来关上的门打开。
) (15分)3. 整型数组,长度为10,输入数组各元后,求数组各元的平均值,并找出最接近平均值的那个元素。
打印输出上述两个结果,用逗号隔开,不要有其它字符。
(20分)4. 编程求两个很长的整数之和,比如两个20位十进制整数。
(很长的整数指无法用long型存储的数)(25分)例如:12345678900987654321+12345678900987654321=246913578019753086425.编写布雷程序。
(30分)在一个10*10的方格中,随机分布10个地雷,并在其它没有地雷的格中显示该方格周围相邻的方格中共有几枚地雷。
样例输出:(图中-1的位置表示地雷,其它值表示该位置相邻的八个格子中的地雷数)答案:第一题:#include <iostream>using namespace std;int main(){int i,j,k;for(i=1;i<=20;i++)for(j=1;j<=50;j++){k=100-5*i-2*j;if(k>0)cout<<"五分硬币"<<i<<"枚,二分硬币"<<j<<"枚,一分硬币"<<k<<"枚"<<endl;}system("pause");return 0;}第二题:#include<iostream>using namespace std;int main(){int i,j; //i为服务员编号,j为房间编号int a[101];for(int t=1;t<101;t++)a[t]=1;for(i=2;i<101;i++)for(j=i;j<101;j++)if(j%i==0) a[j]*=-1;cout<<"打开的房间为:";for(i=1;i<101;i++)if(a==1)cout<<i<<",";system("pause");return 0;}第三题:#include <iostream>#include <math.h>using namespace std;int main(){int a[10],i,sum=0,n=0;float ave,ca;for(i=0;i<10;i++){cin>>a;sum+=a;}ave=sum/10.0;cout<<"数组平均值为:"<<ave<<endl;ca=fabs(a[0]-ave);for(i=1;i<10;i++){if( fabs(a-ave)<ca){ ca=fabs(a-ave);n=i;}}cout<<"最接近平均值的元素为第"<<n+1<<"个"<<a[n]<<endl; system("pause");return 0;}第四题://长整数相加#include <iostream>#include <stdlib.h>#include <time.h>#define LENGTH 10using namespace std;class ClargeInt{static const int SIZE = LENGTH; //整数最长100位int element[SIZE];int _len; // 0 < _len < SIZE 整数的实际位数int _OverFlow; //溢出标记,0 无溢出, 1 溢出public:int* GetPosition() const{return (int*)element;}ClargeInt(void):_OverFlow (0){int i;for (i = 0; i<SIZE; i++){element = 0;_len = SIZE;}}ClargeInt(int *data, int len):_OverFlow(0) {int i;for (i = 0; i < len; i++){element = *(data+i);}_len = len;}ClargeInt(const ClargeInt& a){int i;for (i = 0; i < a._len ; i++){element = a.element;}_len = a._len;}void print(void){int i;for (i = _len - 1 ; i >= 0 ; i--)printf("%1d",element);printf("\n");}int GetLen()const{return _len;}int SetOverFlow(int OverFlow){_OverFlow = OverFlow;}int GetOverFlow(){return _OverFlow ;}const ClargeInt& operator+(const ClargeInt& RValue){ClargeInt temp;int Llen,Rlen,ActualLen;int value;int CarryFlag; //进位标记,产生进位为 1,没有进位为0 CarryFlag = 0;if ( _len >= RValue._len ){ActualLen = _len;for (int i = 0; i < ActualLen; i++){if (i < RValue._len){value = element + RValue.element + CarryFlag; }else{value = element + CarryFlag;}temp.element = value % 10;CarryFlag = value / 10;}}else{ActualLen = RValue._len;for (int i = 0; i < ActualLen; i++){if (i < _len){value = element + RValue.element + CarryFlag; }else{value = RValue.element + CarryFlag;}temp.element = value % 10;CarryFlag = value / 10;}} //the end of iftemp._len = ActualLen ;if (CarryFlag == 1){if (ActualLen < SIZE){temp.element[ActualLen] = CarryFlag;temp._len =ActualLen + 1;}else{temp._OverFlow = 1;temp._len =ActualLen ;}}return temp;} // the end of operator +};int main(){int data1[LENGTH];int data2[LENGTH];int len1, len2;int i;// Seed the random-number generator with current time so that //the numbers will be different every time we run.//srand( (unsigned)time( NULL ) );for (i = 0; i< LENGTH; i++){data1 = rand()%10;}for (i = 0; i< LENGTH-5; i++){data2 = rand()%10;}// InitArray( data1, len1) ;// InitArray( data2, len2) ;ClargeInt Value1 (data1, LENGTH);ClargeInt Value2 (data2, LENGTH-5);ClargeInt SumValue;SumValue =Value1 + Value2;Value1.print();Value2.print();if( SumValue.GetOverFlow()==1){cout<<"相加之和,超出整数长度表示范围!" << endl; }SumValue.print();SumValue = Value2 + Value1;if( SumValue.GetOverFlow()==1){cout<<"相加之和,超出整数长度表示范围!" << endl; }SumValue.print();system("pause");return 0;}第五题:#include "stdio.h"#include "stdlib.h"#include "time.h"int main(){ int b[100];int a[10][10];int i=0,r,k,n,m,l,x,y,bomb;for (i=0;i<100;i++){ b=i;a[i/10][i%10]=20;};i=0;k=100;while (i<10){ srand(time(NULL));r=rand()%k;a[b[r]/10][b[r]%10]=-1;while (r<=k-2){ b[r]=b[r+1];r++;};k--;i++;};for (i=0;i<10;i++)for (r=0;r<10;r++){ if (a[r]!=-1){ k=(((i-1)>0)?(i-1):0);n=(((i+1)<9)?(i+1):9);m=(((r-1)>0)?(r-1):0);l=(((r+1)<9)?(r+1):9);x=k;bomb=0;while (x<=n){ y=m;while (y<=l){ if (a[x][y]==-1) bomb++;y++;};x++;};a[r]=bomb;};};i=0;while (i<10){ printf("\n");r=0;while (r<10){ printf("%4d",a[r]); r++;};i++;};getch();return 0;}。