期末考试补充测验

收藏

编号:168915028    类型:共享资源    大小:622.53KB    格式:PPT    上传时间:2022-11-13
10
积分
关 键 词:
期末考试 补充 测验
资源描述:
期末考试补充测验1.Sum of even numbers2DescriptionGiven 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.OutputFor 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 258Sample Output 6201.Sum of even numbers3#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 Management4DescriptionThere 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.InputTotally,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.OutputEach 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 90LiMing 90HuRui 50ZhangLi 65LiLei 80ZhangFei 65ZhaoSan 70ChenZi 100Sample Output100 ChenZi90 WangYi LiMing80 LiLei70 ZhaoSan65 ZhangLi ZhangFei50 HuRui2.Grade Record Management5#define SIZE 8#define LEN 25int main()char nameSIZELEN;int gradeSIZE;for(int i=0;i namei;cin gradei;/rankfor(int i=SIZE-1;i 0;-i)for(int j=0;j i;+j)if(gradej gradej+1)char tmpLEN;strcpy(tmp,namej);strcpy(namej,namej+1);strcpy(namej+1,tmp);int tmp2=gradej;gradej=gradej+1;gradej+1=tmp2;/printfor(int i=0;i SIZE;+i)if(i=0|gradei gradei-1)cout gradei;cout gradei+1)cout salpcnttarget;while(sal0)yr=1;sum=12*sal;while(sumtarget)sal+=(sal*pcnt)/100;sum+=12*sal;yr+;coutyrsalpcnttarget;2.String Reversion 9DescriptionGiven 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 _.OutputFor each test case,print out the string reversed.Sample Input 2John_Smithint_45_meSample Output nhoJ_htimStni_54_emString Reversion 10void reversePart(char,int,int);/reverse part of the stringint main()int count;cincount;for(int x=0;xstr;for(int i=0;istrlen(str);i+)if(stri=_)mark=i;break;reversePart(str,0,mark-1);reversePart(str,mark+1,strlen(str)-1);coutstrhigh)return;for(int i=low;ich;while(ch!=#)/Initialze vairalbe for each line of input for(int i=0;i-1&countlast0ch;if(countdigit0countdigit1)countdigit0=countdigit1;/Sort the numbers int max,tmp1,tmp2;/Set the second column to be digits 0.9;for(int i=0;i=9;i+)counti1=i;for(int i=0;i=9;i+)max=findMax(count,i);tmp1=counti0;tmp2=counti1;counti0=countmax0;counti1=countmax1;countmax0=tmp1;countmax1=tmp2;/Print out the results for(int i=0;i0)coutcounti1(counti0);if(i0)cout,;else coutch;int findMax(int count2,int low)int max=low;for(int i=low+1;icountmax0)max=i;else if(counti0=countmax0&counti1countmax1)max=i;return max;4.Change to upper case 13Description 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 first 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 case14int length(char*string1)for(int i=0;+i)if(string1i=0)return I;char toUpperCase(char c)if(c=a&c=z)return(char)(c-(a-A);return c;void toUpperCase(char*string1,char*string2)int length1=length(string1);int times=0;int status=1;for(int i=0;i length1;+i)if(string1i=)string2i=string1i;status=1;else if(status=1)string2i=toUpperCase(string1i);else string2i=string1i;status=0;int main()char string1100;char string2100;cin.getline(string1,100);toUpperCase(string1,string2);cout string2;5.Cycling the words 15Description 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 line 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.OutputN 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.Sample Input Please think about it carefullySample Output Please think about it carefullythink about it carefully Pleaseabout it carefully Please thinkit carefully Please think aboutcarefully Please think about itCycling the words16int length(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 length1=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);
展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
提示  装配图网所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
关于本文
本文标题:期末考试补充测验
链接地址:https://www.zhuangpeitu.com/article/168915028.html
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!