freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

程序設(shè)計教程--用c語言編程(第二版)課后答案-資料下載頁

2025-07-27 05:03本頁面
  

【正文】 offset=find_lenreplace_len。 while (strlen(str+index) = find_len) { if (strncmp(str+index,find_str,find_len) == 0) { if (offset 0) //把字符串剩余部分往后移offset個位置 {int n=strlen(str+index)find_len+1。 //剩余部分的字符個數(shù)+1(39。\039。) for (int i=strlen(str)。 n0。 i,n) str[i+(offset)] = str[i]。 } else if (offset 0) //把字符串剩余部分往前移offset個位置 {int n=strlen(str+index)find_len+1。//剩余部分的字符個數(shù)+1(39。\039。) for (int i=index+find_len。 n0。 i++,n) str[ioffset] = str[i]。 } for (int i=0。 ireplace_len。 i++) //復(fù)制被替換成的串到str str[index+i] = replace_str[i]。 index += replace_len。 } else index++。 }}1 編寫一個程序,從鍵盤輸入一批學(xué)生的成績信息,每個學(xué)生的成績信息包括:學(xué)號、姓名以及8門課的成績。然后按照平均成績由高到低順序輸出學(xué)生的學(xué)號、姓名以及平均成績。解:include iostreamusing namespace std。struct Student{ char id[11]。 char name[9]。 double scores[9]。}。int main(){ int n。 cout 請輸入學(xué)生人數(shù):。 cin n。 Student *students=new Student[n]。 //創(chuàng)建動態(tài)數(shù)組以存放學(xué)生信息。 //輸入每個學(xué)生的信息。 int i,j。 for (i=0。 in。 i++) { cout 學(xué)號:。 cin students[i].id。 cout 姓名:。 cin students[i].name。 cout 8門課成績:。 students[i].scores[8] = 。 for (j=0。 j8。 j++) { cin students[i].scores[j]。 students[i].scores[8] += students[i].scores[j]。 } students[i].scores[8] /= 8。 //平均成績 } //根據(jù)平均成績對學(xué)生信息進行排序。 for (i=n。 i1。 i) { bool exchange=false。 for (j=1。 ji。 j++) { if (students[j].scores[8] students[j1].scores[8]) { Student temp=students[j]。 students[j] = students[j1]。 students[j1] = temp。 exchange = true。 } } if (!exchange) break。 } //輸出排序后的學(xué)生信息 for (i=0。 in。 i++) { cout students[i].id 39。,39。 students[i].name 39。,39。 students[i].scores[8] endl。 } return 0。}1 下面的交換函數(shù)正確嗎?void swap_ints(int amp。x, int amp。y){ int amp。tmp=x。 x = y。 y = tmp。}答:不正確,因為temp為引用類型,它與x占有相同的空間,當(dāng)執(zhí)行“x=y?!辈僮髦?,temp的值已不是x原來的值了!按照這個函數(shù),x和y的值會相等并且等于y的值,不能實現(xiàn)將x和y交換的目的。1 寫一個函數(shù)map,它有三個參數(shù)。第一個參數(shù)是一個一維double型數(shù)組,第二個參數(shù)為數(shù)組元素個數(shù),第三個參數(shù)是一個函數(shù)指針,它指向帶有一個double型參數(shù)、返回值類型為double的函數(shù)。函數(shù)map的功能是把數(shù)組的每個元素替換成:用它原來的值(作為參數(shù))調(diào)用第三個參數(shù)所指向的函數(shù)得到的值。解:void map(double d[], int n, double (*fp)(double d)){ for (int i=0。 in。 i++) d[i]=(*fp)(d[i])。 return。}1 把在鏈表中插入一個新結(jié)點的操作寫成一個函數(shù):bool insert(Node *amp。h,int a,int pos)。其中,h為表頭指針,a為要插入的結(jié)點的值,pos(≥0)表示插入位置。當(dāng)pos為0時表示在表頭插入;否則,表示在第pos個結(jié)點的后面插入。操作成功返回true,否則返回false。解:struct Node{ int value。 Node *next。}。bool insert(Node *amp。h,int a,int pos){ Node *q。 if (pos==0) { q=new Node。 qvalue = a。 qnext=h。 h=q。 return true。 } else { Node *p=h。 int i=1。 while (p!=NULL amp。amp。 ipos) { p=pnext。 i++。 } if (p!=NULL) { q=new Node。 qvalue = a。 qnext=pnext。 pnext=q。 return true。 } else return false。 }} 把在鏈表中刪除一個結(jié)點的操作寫成一個函數(shù):bool remove(Node *amp。h,int amp。a, int pos)。其中,h為表頭指針,a用于存放刪除的結(jié)點的值,pos(0)表示刪除結(jié)點的位置。操作成功返回true,否則返回false。解:struct Node{ int value。 Node *next。}。bool remove(Node *amp。h,int amp。a, int pos){ Node *p=h, *q=NULL。 int i=1。 while (p!=NULL amp。amp。 ipos) { q=p。 p=pnext。 i++。 } if (p!=NULL) { a=pvalue。 if (q!=NULL) qnext=pnext。 else h = pnext。 delete p。 return true。 } else return false。}2 編寫一個程序,首先建立兩個集合(從鍵盤輸入集合的元素),然后計算這兩個集合的交集、并集以及差集,最后輸出計算結(jié)果。要求用鏈表實現(xiàn)集合的表示。解:include iostreamusing namespace std。struct Node{ int value。 Node *next。}。bool find(Node *h,int x) //在h中查找x{ for (Node *p=h。 p!=NULL。 p=pnext) if (pvalue == x) return true。 return false。}void insert(Node *amp。h, int x) //在h中增加一個元素{ Node *p=new Node。 pvalue = x。 pnext = h。 h = p。}Node *input() //建立集合{ Node *h=NULL。 int x。 for (cin x。 x != 1。 cin x) { if (find(h,x)) continue。 insert(h,x)。 } return h。}Node *set_union(Node *h1, Node *h2) //集合“并”{ Node *h=NULL,*p。 //生成一個與h1一樣的集合h for (p=h1。 p!=NULL。 p=pnext) insert(h,pvalue)。 //把h2加入到h中(去重) for (p=h2。 p!=NULL。 p=pnext) { if (!find(h1,pvalue)) insert(h,pvalue)。 } return h。}Node *set_intersection(Node *h1, Node *h2) //集合“交”{ Node *h=NULL。 for (Node *p=h1。 p!=NULL。 p=pnext) { if (find(h2,pvalue)) insert(h,pvalue)。 } for (Node *q=h2。 q!=NULL。 q=qnext) { if (!find(h1,qvalue)) insert(h,qvalue)。 } return h。}Node *set_difference(Node *h1, Node *h2) //集合“差”{ Node *h=NULL。 for (Node *p=h1。 p!=NULL。 p=pnext) { if (!find(h2,pvalue)) insert(h,pvalue)。 } return h。}void output(Node *h) //輸出集合的所有元素{ for (Node *p=h。 p!=NULL。 p=pnext) cout pvalue 39。 39。 cout endl。}void remove(Node *amp。h) //刪除集合{ while (h != NULL) { Node *p=h。 h = hnext。 delete p。 }}int main(int argc, char* argv[]){ Node *set1,*set2,*set3,*set4,*set5。 set1 = input()。 set2 = input()。 set3 = set_union(set1,set2)。 set4 = set_intersection(set1,set2)。 set5 = set_difference(set1,set2)。 output(set1)。 output(set2)。 output(set3)。 output(set4)。 output(set5)。 remove(set1)。 remove(set2)。 remove(set3)。 remove(set4)。 remove(set5)。 return 0。}2 在排序算法中,有一種排序算法(插入排序)是:把待排序的數(shù)分成兩個部分: A B其中,A為已排好序的數(shù),B為未排好序的數(shù),初始狀態(tài)下,A中只有一個元素。該算法依次從B中取數(shù)插入到A中的相應(yīng)位置,直到B中的數(shù)取完為止。請在鏈表表示上實現(xiàn)上述的插入排序算法。解:struct Node{ int content。 Node *next。}。void insert_sort(Node *amp。h){ if (h == NULL) return。 Node *q=hnext。 //q指向B部分的第一個元素 hnext = NULL。 //h指向A部分的第一個元素(初始狀態(tài)下,A部分只有一個元素) while (q != NULL)//對第二部分的元素進行循環(huán) { //從B部分取一個元素Node *q1=q。 //q1指向取到的元素q = qnex
點擊復(fù)制文檔內(nèi)容
高考資料相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1