资源描述
单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,*,本资料仅供参考,不能作为科学依据。谢谢。本资料仅供参考,不能作为科学依据。感谢,单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,*,本资料仅供参考,不能作为科学依据。谢谢。本资料仅供参考,不能作为科学依据。感谢,单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,Liang,Introduction to C+Programming,(c)2007 Pearson Education,Inc.All rights reserved.013225445X,*,本资料仅供参考,不能作为科学依据。谢谢。本资料仅供参考,不能作为科学依据。感谢,单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,Liang,Introduction to C+Programming,(c)2007 Pearson Education,Inc.All rights reserved.013225445X,*,本资料仅供参考,不能作为科学依据。谢谢。本资料仅供参考,不能作为科学依据。感谢,单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,Liang,Introduction to C+Programming,(c)2007 Pearson Education,Inc.All rights reserved.013225445X,*,本资料仅供参考,不能作为科学依据。谢谢。本资料仅供参考,不能作为科学依据。感谢,单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,Liang,Introduction to C+Programming,(c)2007 Pearson Education,Inc.All rights reserved.013225445X,*,本资料仅供参考,不能作为科学依据。谢谢。本资料仅供参考,不能作为科学依据。感谢,单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,Liang,Introduction to C+Programming,(c)2007 Pearson Education,Inc.All rights reserved.013225445X,*,本资料仅供参考,不能作为科学依据。谢谢。本资料仅供参考,不能作为科学依据。感谢,单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,Liang,Introduction to C+Programming,(c)2007 Pearson Education,Inc.All rights reserved.013225445X,*,本资料仅供参考,不能作为科学依据。谢谢。本资料仅供参考,不能作为科学依据。感谢,单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,Liang,Introduction to C+Programming,(c)2007 Pearson Education,Inc.All rights reserved.013225445X,*,本资料仅供参考,不能作为科学依据。谢谢。本资料仅供参考,不能作为科学依据。感谢,单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,Liang,Introduction to C+Programming,(c)2007 Pearson Education,Inc.All rights reserved.013225445X,*,本资料仅供参考,不能作为科学依据。谢谢。本资料仅供参考,不能作为科学依据。感谢,单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,Liang,Introduction to C+Programming,(c)2007 Pearson Education,Inc.All rights reserved.013225445X,*,本资料仅供参考,不能作为科学依据。谢谢。本资料仅供参考,不能作为科学依据。感谢,单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,Liang,Introduction to C+Programming,(c)2007 Pearson Education,Inc.All rights reserved.013225445X,*,本资料仅供参考,不能作为科学依据。谢谢。本资料仅供参考,不能作为科学依据。感谢,单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,Liang,Introduction to C+Programming,(c)2007 Pearson Education,Inc.All rights reserved.013225445X,*,本资料仅供参考,不能作为科学依据。谢谢。本资料仅供参考,不能作为科学依据。感谢,单击此处编辑母版标题样式,单击此处编辑母版文本样式,第二级,第三级,第四级,第五级,Liang,Introduction to C+Programming,(c)2007 Pearson Education,Inc.All rights reserved.013225445X,*,本资料仅供参考,不能作为科学依据。谢谢。本资料仅供参考,不能作为科学依据。感谢,期末考试补充测验,1/16,1.Sum of even numbers,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,2/16,2,1.Sum of even numbers,#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;,coutsum namei;cin gradei;,/rank,for(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;,/print,for(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;,8/16,8,2.String Reversion,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,9/16,9,String Reversion,void reversePart(char,int,int);/reverse part of the string,int 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;,12/16,12,4.Change to upper case,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 first character of each word being upper case.,Sample Input,Please change me to upper-case.,Sample Output,Please Change Me To Upper-case.,13/16,13,Change to upper case,int length(char*string1),for(int i=0;+i)if(string1i=0)return I;,char toUpperCase(char c),if(c=a,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;,14/16,14,5.Cycling the words,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 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.,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.,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,15/16,15,Cycling the words,int 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);,16/16,16,
展开阅读全文