Acm试题及答案

合集下载

计算机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程序大赛选拔初赛试题 - 参考答案

《解方程》参考答案:
#include <stdio.h> #include <math.h> void main() {
int a,b,c,d; float x1,x2; scanf("%d %d %d %d",&a,&b,&c,&d); if(a==0) printf("x=%.2f",(float)(d-c)/b); else {
float dr=b*b-4*a*c; c-=d; if(dr>0) {
x1=(-b-sqrt(dr))/(2*a); x2=(-b+sqrt(dr))/(2*a); printf("x1=%.2f x2=%.2f\n",x1,x2); } if(dr==0) { x1=(-b+sqrt(dr))/(2*a); printf("x=%.2f\n",x1); } if(dr<0) printf("no answer\n"); } }
3、计算器 (难度系数:★★★☆☆)
题意:输入一个没有答案的算术式子,用计算机求出输出它的结果。 输入:一个字符串形如“a#b=”(#代表运算符号)。注意:输入的字符串中 a,b 代表的数 都为自然数。而且 a,b 的范围都是从 0 到 999。 输出:字符串对应的算式的答案。答案需保留两位有效数字。若无答案则输出“error” 示例:
输出:第1 行是选出顺序,第2 行是两名幸运儿的开始位置(按升序排列),位置编号之 间用一个空格分开。
示例:
输入(只选一组) 3 5 12
输出(幸运儿的位置)
2 13 241 53 2 4 6 8 10 12 3 7 11 5 19

计算机学院ACM设计大赛初赛试题

计算机学院ACM设计大赛初赛试题

计算机学院ACM设计大赛初赛试题问题一:给定一个N位的二进制串b1 b2 …bN-1 bN将该串做旋转,即将b1移到bN后面,得到一个新的二进制串:b2 …bN-1 bN b1对新的二进制串再做旋转,得二进制串b3 b4 …bN-1 bN b1 b2重复旋转操作操作,可得N个二进制串,对这N个串排序,可得一个N*N的矩阵问:给定这种矩阵的最后一列,求出矩阵的第一行。

对于上面的例子,给出1 0 0 1 0,要你的程序输出0 0 0 1 1。

原题描述:Binary codesTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 4881 Accepted: 1847DescriptionConsider a binary string (b1…b N) with N binary digits. Given such a string, the matrix of Figure 1 is formed from the rotated versions of the string.b 1b2…b N−1b Nb 2b3…b N b1…b N−1b N…b N−3b N−2b N b1…b N−2b N−1Figure 1. The rotated matrixThen rows of the matrix are sorted in alphabetical order, where ‘0’ is before ‘1’. You are to write a program which, given the l ast column of the sorted matrix, finds the first row of the sorted matrix.As an example, consider the string (00110). The sorted matrix is0 0 0 1 10 0 1 1 00 1 1 0 01 0 0 0 11 1 0 0 0and the corresponding last column is (1 0 0 1 0). Given this last column your program should determine the first row, which is (0 0 0 1 1).InputThe first line contains one integer N≤ 3000, the number of binary digits in the binary string. The second line contains N integers, the binary digits in the last column from top to bottom.OutputThe first line contains N integers: the binary digits in the first row from left to right. Sample Input51 0 0 1 0Sample Output0 0 0 1 1问题二:某地的交通网由路口和公路构成:两个路口之间最多有一条公路,公路两个方向的行驶时间相同。

acm竞赛试题及答案

acm竞赛试题及答案

acm竞赛试题及答案ACM(Association for Computing Machinery)竞赛是一项全球性计算机科学竞赛,旨在锻炼参赛者的问题解决能力和编程技巧。

每年都有数千名来自不同学校的学生参加这一挑战。

本文将提供一些最近的ACM竞赛试题以及相应的答案,帮助读者了解和学习竞赛题目的类型和解题思路。

1. 问题描述给定一个由N个整数组成的数组A,请编写一个程序,找出数组中两个不同元素的差的最小值。

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

- 第二行包含N个以空格分隔的整数,表示数组A中的元素。

3. 输出格式输出一个整数,表示数组中两个不同元素的差的最小值。

4. 示例输入:51 52 9 12输出:15. 解题思路该问题可以通过对数组进行排序,并比较相邻两个数的差值来求解。

首先,将数组A进行升序排序。

然后,遍历排序后的数组,依次计算相邻两个数的差值,并记录其中的最小值。

最后,返回这个最小差值即可。

6. 代码实现```pythondef min_difference(nums):nums.sort() # 对数组进行升序排序min_diff = float('inf') # 初始化最小差值为正无穷大for i in range(len(nums)-1):diff = abs(nums[i] - nums[i+1]) # 计算相邻两个数的差值min_diff = min(min_diff, diff) # 更新最小差值return min_diff# 输入处理N = int(input())A = list(map(int, input().split()))# 调用函数并输出结果result = min_difference(A)print(result)```7. 答案解析对给定的数组进行排序后,遍历数组计算相邻两个数的差值,并记录其中的最小值。

上述代码中,首先将数组A进行升序排序,然后使用一个变量`min_diff`来记录最小差值。

思想道德与法律基础试题及答案acm

思想道德与法律基础试题及答案acm

思想道德修养与法律基础考试试题(含答案)一、单项选择题1.由于生产力发展水平不同,社会性质和人们所处经济政治文化地位不同,所处的阶级关系与阶级地位不同,对社会发展规律认识和把握的深度与广度不同,所以形成的理想也必然不同,这说明理想具有()【答案】CA、社会性和变化性B、民族性与多样性C、时代性和阶级性D、随意性与不确定性2.理想信念对每个人的人生意义重大,理想信念的作用主要表现在:提供人生的前进动力、提高人生的精神境界和()【答案】BA、提高人生的知识含量B、指引人生的奋斗目标C、增加人生的财富水平D、使人生一帆风顺3.全国人民代表大会是由( ) 。

【答案】DA、各省、市、县的人民代表大会选出的代表组成B、各省、市、县的人民代表大会和军队选出的代表组成C、各省、自治区、直辖市的人民代表大会选出的代表组成D、各省、自治区、直辖市的人民代表大会和军队选出的代表组成4.爱国主义包含着情感、思想、行为三个方面,其中灵魂是()【答案】BA、情感B、思想C、行为D、意志5.鲁迅说:“唯有民魂是值得宝贵的”鲁迅说的民魂是指()【答案】AA、中华民族精神B、中华文化C、中国的脊梁D、创新和发展的思想6.在阶级社会中,爱国主义具有()【答案】AA、阶级性B、统一性C、差异性D、对立性7.区别高尚充实的人生与庸俗空虚的人生的是()【答案】CA、有无崇高的道德修养B、有无丰富的科学文化知识C、有无科学而崇高的理想信念D、有无积极向上的精神追求8.实现理想的思想基础是()【答案】BA、解放思想B、正确认识理想与现实的关系C、创新思维D、阶级分析方法9.解决台湾问题,实现祖国完全统一,是全体中华儿女的共同心愿,是中华民族的()【答案】BA、“大一统”价值观的体现B、根本利益所在C、大团圆的需要D、民族情感的需要10.社会主义社会占统治地位的价值观念是()【答案】AA、公有观念B、私有观念C、民有观念D、共有观念11.人生观的核心是()【答案】BA、人生价值B、人生目的C、人生态度D、人生信仰12.人们在实践中形成的对人生目的和意义的根本看法和态度是()【答案】CA、世界观B、自然观C、人生观D、价值观13.人生价值观是()【答案】DA、产生于主体的需要和客观满足主体需要的关系中B、自我价值与社会价值的统一C、对人为什么活着的基本观点D、对人生目的和实践活动进行认识和评价时所持的基本观点14.一定社会或阶级根据其总的道德要求制定的,调节人们在家庭生活方面的关系和行为的道德准则称为()【答案】DA、家庭义务B、男女平等C、一夫一妻制D、家庭道德15.为调整和规范人类社会生活三大领域,相应分别形成了:()【答案】DA、生活道德、职业道德、家庭道德B、生活道德、职业道德、社会公德C、社会公德、生活道德、职业道德D、社会公德、职业道德、家庭美德16.()是指道德反映社会现实特别是反映社会经济关系的功效与能力【答案】BA、道德的功能B、道德的认识功能C、道德的调节功能D、道德的社会功能17.人类道德的发展,是一个()的过程【答案】CA、直线上升B、斜线上升C、曲折上升D、徘徊停滞不前18.()是指社会对个人履行社会义务给予的褒扬和赞许以及个人所产生的自我肯定性心理体验【答案】CA、名誉B、嘉奖C、荣誉D、表彰19.一个民族得以延续的“精神基因”是()【答案】BA、民族心理B、民族文化C、国家主权D、爱国传统20.新时期爱国主义的基本特征是坚持爱国主义与(A)A.爱社会主义 B.爱人民群众C.爱中国共产党D.爱本职工作21.增强国防观念,是保障国家安全的需要,是增强民族凝聚力和向心力的“黏合剂”,因而也是新时期(C)A.中华民族发展需要 B、维护世界和平的要求C、爱国主义的重要内容D.国家强大的标志22.科学理想信念的理论基础是(C)A、哲学B、社会学C、马克思主义D、逻辑学23.大学生要树立马克思主义的信仰,因为马克思主义是科学而崇高的、马克思主义具有持久的生命力、(A)A、马克思主义以改造世界为己任B、马克思主义是理论C、马克思主义学术价值高D、马克思主义是伟人马克思、恩格斯创立的24.以下关于爱国主义与拥护祖国统一具有一致性的正确说法是(A)。

acm编程比赛题

acm编程比赛题

比赛试题主办方:迅翔计算机协会【问题描述】这是一个古老而又经典的问题。

用给定的几种钱币凑成某个钱数,一般而言有多种方式。

例如:给定了6种钱币面值为2、5、10、20、50、100,用来凑15元,可以用5个2元、1个5元,或者3个5元,或者1个5元、1个10元,等等。

显然,最少需要2个钱币才能凑成15元。

你的任务就是,给定若干个互不相同的钱币面值,编程计算,最少需要多少个钱币才能凑成某个给出的钱数。

【要求】【数据输入】输入可以有多个测试用例。

每个测试用例的第一行是待凑的钱数值M(1 <= M <= 2000,整数),接着的一行中,第一个整数K(1 <= K <= 10)表示币种个数,随后是K 个互不相同的钱币面值Ki(1 <= Ki <= 1000)。

输入M=0时结束。

【数据输出】每个测试用例输出一行,即凑成钱数值M最少需要的钱币个数。

如果凑钱失败,输出“Impossible”。

你可以假设,每种待凑钱币的数量是无限多的。

【样例输入】156 2 5 10 20 50 10011 2【样例输出】2Impossible【问题描述】Felicia 的生日是11月1日(和Kitty是同一天生的哦)。

于是Feli请来Kitty一起过生日。

Kitty带来了最新款的“Kitty猫”玩具准备送给Feli,不过她说,这份礼物可不是白送的。

Feli要帮她一个忙,才能够得到心仪已久的玩具。

Kitty说,“Kitty猫”玩具已经卖出了n!个,n<=10^100 *_*,Kitty想知道确切的数字,而不是无聊的“一个数加个感叹号”。

Feli 听了大吃一惊。

要知道,算出n!是一个无比艰巨的任务。

Feli告诉Kitty,就算Feli算出n!,Kitty也看不下去,因为当n=20 时,计算机的长整型已经存不下了(Kitty只能接受1-9之间的数字)。

于是Kitty说,你只要告诉我n!最后一位非0的数就可以了。

大一acm竞赛试题及答案

大一acm竞赛试题及答案

大一acm竞赛试题及答案一、选择题(每题5分,共20分)1. 下列哪个算法的时间复杂度为O(n^2)?A. 快速排序B. 归并排序C. 插入排序D. 冒泡排序答案:C2. 在C++中,下列哪个关键字用于定义类?A. structB. classC. unionD. enum答案:B3. 下列哪个数据结构适合用于实现稀疏矩阵?A. 顺序存储B. 链式存储C. 压缩存储D. 散列存储答案:C4. 在图论中,下列哪个算法用于寻找最短路径?A. 深度优先搜索B. 广度优先搜索C. 迪杰斯特拉算法D. 弗洛伊德算法二、填空题(每题5分,共20分)1. 在二叉树的遍历算法中,______遍历会先访问根节点。

答案:前序2. 哈希表的冲突解决方法之一是______。

答案:链地址法3. 在数据库中,用于实现一对多关系的表结构是______。

答案:外键4. 动态规划算法的核心是______。

答案:状态转移方程三、编程题(每题30分,共60分)1. 编写一个函数,实现对一个整数数组进行排序,并返回排序后的数组。

答案:```pythondef sort_array(arr):arr.sort()return arr```2. 编写一个函数,实现计算给定整数n的阶乘。

答案:```pythondef factorial(n):if n == 0:return 1return n * factorial(n - 1)```四、算法题(每题30分,共30分)1. 给定一个整数数组,请设计一个算法找出数组中第二大的数。

答案:```pythondef find_second_max(nums):first_max = second_max = float('-inf')for num in nums:if num > first_max:second_max = first_maxfirst_max = numelif num > second_max and num != first_max:second_max = numreturn second_max```。

Acm试题及答案

Acm试题及答案

Acm试题及答案Acm试题及答案1001 Sum Problem (2)1089 A+B for Input-Output Practice (I) (3) 1090 A+B for Input-Output Practice (II) (4) 1091A+B for Input-Output Practice (III) (6) 1092A+B for Input-Output Practice (IV) (7) 1093 A+B for Input-Output Practice (V) (9) 1094 A+B for Input-Output Practice (VI) (11) 1095A+B for Input-Output Practice (VII) (12) 1096 A+B for Input-Output Practice (VIII) (14) 2000 ASCII码排序 (15)2001计算两点间的距离 (16)2002计算球体积 (17)2003求绝对值 (18)2004成绩转换 (19)2005第几天? (20)2006求奇数的乘积 (22)2007平方和与立方和 (23)2008数值统计 (24)2009求数列的和 (25)2010水仙花数 (27)2011多项式求和 (28)2012素数判定 (29)2014青年歌手大奖赛_评委会打分 (31)2015偶数求和 (32)2016数据的交换输出 (34)2017字符串统计 (35)2019数列有序! (37)2020绝对值排序 (38)2021发工资咯:) (40)2033人见人爱A+B (41)2039三角形 (43)2040亲和数 (44)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解答:#includemain(){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);}}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解答:#includemain(){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#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++)< bdsfid="216" p=""></n;i++)<> {scanf("%d%d",&a,&b);//printf("%d %d",a,b);j[i]=a+b;}i=0;while(i<n)< bdsfid="224" p=""></n)<>{printf("%d",j[i]); i++;printf("\n");}}1091A+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解答:#includemain(){int a,b;scanf("%d %d",&a,&b);while(!(a==0&&b==0)){printf("%d\n",a+b);scanf("%d %d",&a,&b);}}1092A+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 followin 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.Sample Input4 1 2 3 45 1 2 3 4 5Sample Output1015AuthorlcyRecommendJGShining解答:#includeint main(){int n,sum,i,t;while(scanf("%d",&n)!=EOF&&n!=0)sum=0;for(i=0;i<n;i++)< bdsfid="290" p=""></n;i++)<>{scanf("%d",&t);sum=sum+t;}printf("%d\n",sum); }1093 A+B for Input-Output Practice (V)Problem DescriptionYour task is to calculate the sum of some integers.InputInput contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.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.Sample Input24 1 2 3 45 1 2 3 4 5Sample Output1015Authorlcy解答:#includemain()int n,a,b,i,j,sum;sum=0;while(scanf("%d\n",&n)!=-1){for(i=0;i<n;i++)< bdsfid="322" p=""></n;i++)<>{scanf("%d",&b);for(j=0;j<b;j++)< bdsfid="326" p=""></b;j++)<>{scanf("%d",&a);sum+=a;}printf("%d\n",sum); sum=0;}}}1094 A+B for Input-Output Practice(VI)Problem DescriptionYour task is to calculate the sum of some integers.InputInput contains multiple test cases, and one case one line. Each case starts with an integer N, and then N integers follow in the same line.OutputFor each test case you should output the sum of N integers in one line, and with one line of output for each line in input.Sample Input4 1 2 3 45 1 2 3 4 5Sample Output1015AuthorlcyRecommendJGShining解答:#includemain(){int n,a,b,i,j,sum;sum=0;while(scanf("%d\n",&n)!=-1) {for(j=0;j<n;j++)< bdsfid="362" p=""></n;j++)<>{scanf("%d",&a);sum+=a;}printf("%d\n",sum); sum=0;}}1095A+B for Input-Output Practice (VII)Problem DescriptionYour task is to Calculate a + b.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, and followed by a blank line.Sample Input1 510 20Sample Output630AuthorlcyRecommendJGShining解答:#includemain(){int a,b;while(scanf("%d%d",&a,&b)!=EOF)printf("%d\n\n",a+b);}1096 A+B for Input-Output Practice(VIII)Problem DescriptionYour task is to calculate the sum of some integers.InputInput contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.OutputFor each group of input integers you should output their sumin one line, and you must note that there is a blank line between outputs.Sample Input34 1 2 3 45 1 2 3 4 53 1 2 3Sample Output10156AuthorlcyRecommendJGShining解答:int main(){int a,b,i,j,l[1000],k;scanf("%d",&i);getchar();for(j=1;j<=i;j++)l[j]=0;for(j=1;j<=i;j++){scanf("%d",&a);getchar();for(k=1;k<=a;k++){scanf("%d",&b);getchar();l[j]+=b;}}for(j=1;j<=i-1;j++)printf("%d\n\n",l[j]);printf("%d\n",l[i]);}2000 ASCII码排序Problem Description输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。

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

Acm试题及答案1001 Sum Problem (2)1089 A+B for Input-Output Practice (I) (4)1090 A+B for Input-Output Practice (II) (6)1091 A+B for Input-Output Practice (III) (8)1092 A+B for Input-Output Practice (IV) (9)1093 A+B for Input-Output Practice (V) (11)1094 A+B for Input-Output Practice (VI) (12)1095 A+B for Input-Output Practice (VII) (13)1096 A+B for Input-Output Practice (VIII) (14)2000 ASCII码排序 (16)2001计算两点间的距离 (17)2002计算球体积 (19)2003求绝对值 (20)2004成绩转换 (21)2005第几天 (22)2006求奇数的乘积 (24)2007平方和与立方和 (26)2008数值统计 (27)2009求数列的和 (28)2010水仙花数 (29)2011多项式求和 (31)2012素数判定 (33)2014青年歌手大奖赛_评委会打分 (34)2015偶数求和 (36)2016数据的交换输出 (38)2017字符串统计 (40)2019数列有序! (41)2020绝对值排序 (43)2021发工资咯:) (45)2033人见人爱A+B (46)2039三角形 (48)2040亲和数 (49)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<>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); }}1089 A+B for Input-OutputPractice (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<>main(){int a,b;while(scanf("%d%d",&a,&b)!=EOF) printf("%d\n",a+b);}1090 A+B for Input-OutputPractice (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<>#define M 1000void main(){int a ,b,n,j[M],i;1091AInputInput 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<>main(){int a,b;scanf("%d %d",&a,&b);while(!(a==0&&b==0)){printf("%d\n",a+b);scanf("%d %d",&a,&b);}}1092A+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.Sample Input4 1 2 3 45 1 2 3 4 5Sample Output1015AuthorlcyRecommendJGShining解答:#include <>int main(){int n,sum,i,t;while(scanf("%d",&n)!=EOF&&n!=0) {sum=0;for(i=0;i<n;i++){scanf("%d",&t);sum=sum+t;}printf("%d\n",sum);}1093 A+B for Input-Output Practice (V)Problem DescriptionYour task is to calculate the sum of some integers.InputInput contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.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.Sample Input24 1 2 3 45 1 2 3 4 5Sample Output1015Authorlcy解答:#include<>main(){int n,a,b,i,j,sum;sum=0;while(scanf("%d\n",&n)!=-1){for(i=0;i<n;i++){scanf("%d",&b);for(j=0;j<b;j++){scanf("%d",&a); sum+=a;}printf("%d\n",sum); sum=0;}}}1094 A+B for Input-OutputPractice (VI)Problem DescriptionYour task is to calculate the sum of some integers.InputInput contains multiple test cases, and one case one line. Each case starts with an integer N, and then N integers follow in the same line.OutputFor each test case you should output the sum of N integers in one line, and with one line of output for each line in input.Sample Input4 1 2 3 45 1 2 3 4 5Sample Output1015AuthorlcyRecommendJGShining解答:#include<>main(){int n,a,b,i,j,sum;sum=0;while(scanf("%d\n",&n)!=-1) {for(j=0;j<n;j++){scanf("%d",&a); sum+=a;}printf("%d\n",sum); sum=0;}}1095A+B for Input-Output Practice (VII)Problem DescriptionYour task is to Calculate a + b.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, and followed by a blank line.Sample Input1 510 20Sample Output630AuthorlcyRecommendJGShining解答:#include<>main(){int a,b;while(scanf("%d%d",&a,&b)!=EOF)printf("%d\n\n",a+b);}1096 A+B for Input-OutputPractice (VIII)Problem DescriptionYour task is to calculate the sum of some integers.InputInput contains an integer N in the first line, and then N lines follow. Each line starts with a integer M, and then M integers follow in the same line.OutputFor each group of input integers you should output their sum in one line, and you must note that there is a blank line between outputs.Sample Input34 1 2 3 45 1 2 3 4 53 1 2 3Sample Output10156AuthorlcyRecommendJGShining解答:int main(){int a,b,i,j,l[1000],k;scanf("%d",&i);getchar();for(j=1;j<=i;j++)l[j]=0;for(j=1;j<=i;j++){scanf("%d",&a);getchar();for(k=1;k<=a;k++){scanf("%d",&b);getchar();l[j]+=b;}}for(j=1;j<=i-1;j++)printf("%d\n\n",l[j]);printf("%d\n",l[i]);}2000 ASCII码排序Problem Description输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。

相关文档
最新文档