资源预览内容
第1页 / 共16页
第2页 / 共16页
第3页 / 共16页
第4页 / 共16页
第5页 / 共16页
第6页 / 共16页
第7页 / 共16页
第8页 / 共16页
第9页 / 共16页
第10页 / 共16页
亲,该文档总共16页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
期末考试补充测验,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 follow 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,#include 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”. 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 appear 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 the 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,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; ,期末考试,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 exceed 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 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 case, 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*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 number 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,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; ,3. Count of Consecutive Numbers,11,Description Given an sequence of digits, 09, 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 maximum 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 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(occurrence 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; while(ch!=#) /Initialze vairalbe for each line of inp
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号