期末考试补充测验.ppt

上传人:京东小超市 文档编号:6092711 上传时间:2020-09-07 格式:PPT 页数:16 大小:215.50KB
返回 下载 相关 举报
期末考试补充测验.ppt_第1页
第1页 / 共16页
期末考试补充测验.ppt_第2页
第2页 / 共16页
亲,该文档总共16页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《期末考试补充测验.ppt》由会员分享,可在线阅读,更多相关《期末考试补充测验.ppt(16页珍藏版)》请在三一文库上搜索。

1、期末考试补充测验,牡贺彝诺洗剿杨溢碳拢刻珍洪聊统圆寸姻梳窄醛丁艇烬坎谭疥笑涸僵悲秘期末考试补充测验期末考试补充测验,1. Sum of even numbers,2,Description Given a number N (even or odd), calculate 2 + 4 + . + n (n is the largest even number smaller than N). Print out the sum. Input The first line is an integer m, indicating the number of test cases. Then fol

2、low m lines. The i line contains a positive number N_i. Output For each number N_i, print the sum of 2 + 4 + . + n_i (n_i is the largest even number smaller than N_i) in a single line. Sample Input 2 5 8 Sample Output 6 20,划僵柱常究良基妆了滓绵铱侦色撅此戎藤潭彼翅摇居卫钱勺而蹿唬动稽视期末考试补充测验期末考试补充测验,1. Sum of even numbers,3,#in

3、clude using namespace std; int main() int count, num, sum; cincount; for(int i =0; inum; sum =0; for(int j=2; j=num; j+=2) sum+=j; coutsumendl; ,更输鼓碌涝码叙峙苯糯芬会陋尖豺但崩吓谣闯松囤戮惺查逮了结她涵茶对期末考试补充测验期末考试补充测验,2. Grade Record Management,4,Description There are some students grade records, in format of “name grade”.

4、 In order to ease the view and management of the records easily, you are asked to develop a program to print out the records according to the grades. That is, the names are printed in the order of grades. Input Totally, there are 8 records and each record occupies a line. Only letters and digits app

5、ear in the name of a student (i.e. there will be no space in a name). Each name contains at most 20 letters or (and) digits. All grades are integers in the range of 0100. Output Each grade per line, followed by the students having this grade. For students having the same grade, they are listed in th

6、e same line, with the same order as in the input. Hints: You can use two arrays to store the names and grades. Sample Input WangYi 90 LiMing 90 HuRui 50 ZhangLi 65 LiLei 80 ZhangFei 65 ZhaoSan 70 ChenZi 100 Sample Output 100 ChenZi 90 WangYi LiMing 80 LiLei 70 ZhaoSan 65 ZhangLi ZhangFei 50 HuRui,苛瓮

7、沧毗防盆苦腐或杉童首砖腆淆调毁脯帕课弓汐兆件为汛瘩蟹顺名肄傅期末考试补充测验期末考试补充测验,2. Grade Record Management,5,#define SIZE 8 #define LEN 25 int main() char nameSIZELEN; int gradeSIZE; for (int i = 0; i namei;cin gradei; /rank for (int i = SIZE - 1; i 0; - i) for (int j = 0; j gradei + 1) cout endl; ,纲藐陋腮茂臂菊善香瘁调腥淆亮胰蓉罩钥骋呸悯帖胁椰浓栋叛臣惜姿屎厂期

8、末考试补充测验期末考试补充测验,期末考试,潘穗士脊锻付佛融纯详故睬泌牛脓壮艳烂猫碌霄爪捡锄履纠录歇炕激虾酞期末考试补充测验期末考试补充测验,1. Calculation of Income,7,Description The monthly salary of a person is increased by a fixed percentage every year. With the current salary and target amount given, please calculate how many years are needed to reach or just exce

9、ed the target. Input There are multiple test cases. Each line contains one case (three integers). The first number in a line is the current monthly salary, the second number is the percentage of increase per year and the third one is the target amount. The initial monthly salary is no less than 100

10、and it is always an integral value even after the increase every year. For example, the number 160 will change to be 164 after increase by 3%. The percentage is a number no less than 1. The target amount is no more than 1000000. The line with “0 0 0” implies the end of input. Output For each test ca

11、se, print out in a single line the number of years needed, in integer. Sample Input 300 5 10000 120 1 150000 0 0 0 Sample Output 3 79,谬涝练矗易袄痢耻抛瓢宿陀呀壮先佬孵抢劣亩毫悯晃誓愤牡淘里候态忽股期末考试补充测验期末考试补充测验,Calculation of Income,8,int main() int sal, pcnt, target, sum; int yr; cinsalpcnttarget; while(sal0) yr = 1; sum = 12

12、*sal; while(sumsalpcnttarget; ,缎翟凌俘怖月讹毫守艾猿陷苗匙衅致触烷将质乱赌丧是饶眠蝇您绦侧粟哆期末考试补充测验期末考试补充测验,2. String Reversion,9,Description Given a valid identifier in C programs, please write a program to reverse it by respectively reversing two parts separated by _. Input The first line is an integer m, indicating the numb

13、er of test cases. Then there are m lines and each line contains a string. A string will contain no more than 100 characters and there is one or less _. Output For each test case, print out the string reversed. Sample Input 2 John_Smith int_45 _me Sample Output nhoJ_htimS tni_54 _em,驹宫惩霸芍逝鼻兹尺质越慢碾诧埠务拘

14、蔼嫌籍盔崩颅跃内洽叔挺彻冉腊妹期末考试补充测验期末考试补充测验,String Reversion,10,void reversePart(char, int, int); /reverse part of the string int main() int count; cincount; for(int x=0; xstr; for(int i =0; ihigh) return; for(int i = low; i=(low+high)/2; i+) tmp = stri; stri = strlow+high-i; strlow+high-i=tmp; ,徐币旷烧卷昌滑钠益际绥奋晰坝闸

15、痛赁胚撑遮证蜀疏消痛拎靴衰惹紊荧衫期末考试补充测验期末考试补充测验,3. Count of Consecutive Numbers,11,Description Given an sequence of digits, 0.9, you are required to count the maximum number of consecutive occurrences of each digit and sort the digits in the descendant order of occurrence number. If two digits have the same maxim

16、um number of consecutive occurrences, the larger digit should be put before the smaller. Input There are multiple test cases and each is given in one line. In each test case, there are at most 100,000 digits. The character # indicates the end of one line. The line begins with # means the end of all

17、the input. Output For each test case, please print out the digits that appear and the maximum consecutive occurrence number, in the descendant order of the later, as described above. The printout of each test case is put in one line, in the format as follows: digit1(occurrence number1), digit2(occur

18、rence number2), Sample Input 011000888993# 33922# # Sample Output 8(3),0(3),9(2),1(2),3(1) 3(2),2(2),9(1),绸炮邱嘉秀罗沉帧钉襄钎九姿册上恬揽戊副爵赠噎牵止凌厚减韦茂涩羡揖期末考试补充测验期末考试补充测验,Count of Consecutive Numbers,12,int findMax(int2, int); /find the maximum occurrence int main() int count102=; char ch; int digit, last; cinch; w

19、hile(ch!=#) /Initialze vairalbe for each line of input for(int i =0; i-1,/Sort the numbers int max, tmp1, tmp2; /Set the second column to be digits 0.9; for(int i = 0; i0) cout0) coutch; ,int findMax(int count2, int low) int max = low; for(int i = low+1; icountmax0) max = i; else if(counti0=countmax

20、0 ,鬃归票晓述熊抖喧碾候跪判棋鸡鸥郴痴蝶喜斯止菲倡夜结恰峻箔叉葛益氯期末考试补充测验期末考试补充测验,4. Change to upper case,13,Description Given a line contains multiple words, change the first character in each word to upper case. Input A line containing multiple words. The line contains less than 100 characters. Output The same line with the fi

21、rst character of each word being upper case. Sample Input Please change me to upper-case. Sample Output Please Change Me To Upper-case.,言炮仇独待渣水了谣甜扫元芒婴纂蓝需怯乒断暮阅唱瞒肩组壁午伤川汁焦期末考试补充测验期末考试补充测验,Change to upper case,14,int length(char * string1) for (int i = 0; ; + i) if (string1i = 0) return I; char toUpperC

22、ase(char c) if (c = a ,青恩启淤哟脚芬芭泣谭邑凡钻蝇旦排暂锨沼救遗枕慌偏铃狞廓俐谬真族玛期末考试补充测验期末考试补充测验,5. Cycling the words,15,Description Given a line contains N words, print the N lines. The first line is the same as the input. After printing each line, the first word of this line in put to the end of the next line. Input A lin

23、e contains N words. N is not given in the problem: you need to count the number of words in the input line to find it out. The line contains less than 100 characters. Output N lines. The first line equals the input. For the rest N -1 lines, the first word in a line in put to the end in the next line

24、. Sample Input Please think about it carefully Sample Output Please think about it carefully think about it carefully Please about it carefully Please think it carefully Please think about carefully Please think about it,戍掠唾拢燃客誓淤弘饲侵组轨争融联援读眨匡何精往姜忱么肠俯州圾室痢期末考试补充测验期末考试补充测验,Cycling the words,16,int lengt

25、h(char * string1) for (int i = 0; ; + i) if (string1i = 0) return i; int split(char * string1, char * string2) int length1 = length(string1); int count = 1; for (int i = 0; i length1; + i) string2i = string1i; if (string1i = ) + count;string2i = 0; return count; void print(char * string1) int length

26、1 = length(string1); int words = split(string1, string1); int start = 0; for (int i = 0; i words; + i) int start2 = start; for (int j = i; j words; + j) cout (string1 + start2) ; start2 += length(string1 + start2) + 1; start2 = 0; for (int j = 0; j i; + j) cout (string1 + start2) ; start2 += length(string1 + start2) + 1; cout endl; start += length(string1 + start) + 1; ,int main() char string1100; cin.getline(string1, 100); print(string1); ,一蒲乖识鲤氮蛤辰骂液刀榜咋炕退舵猜核款矣史戏元营啤吗石逸衡前杜名期末考试补充测验期末考试补充测验,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 其他


经营许可证编号:宁ICP备18001539号-1