




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、1. 利用遞歸調(diào)用手段編程計(jì)算N!答:#include<iostream>using namespace std;int t;int n;int Find(int n)if (n = 1)return 1;elset = Find(n-1) * n;return t;int main(void)cin>>n;int t = Find(n);cout<<n<<"! = "<<t<<endl;return 0;2. 寫(xiě)一個(gè)八進(jìn)制轉(zhuǎn)換為十進(jìn)制的問(wèn)題的程序。(設(shè)八進(jìn)制數(shù)只有兩位數(shù)的)#include<io
2、stream>using namespace std;unsigned int oct2dec(unsigned int oct)return oct /10 * 8 +oct %10;int main(void)unsigned int oct = 0;unsigned int dec = 0;cout<<”please input a octet number (Be sure the number you input is begin with a 0):”<<n;cin>>oct;dec = oct2dec(oct);cout<<d
3、ec<<endl;return 0;3. 寫(xiě)出二分查找的代碼.int binary_search(int *arr, int key, int n) int low = 0; int high = n - 1; int mid; while (low <= high) mid = (high + low) / 2; if (arrmid > key) high = mid - 1; else if (arrmid < key) low = mid + 1; else return mid; return -1; *4.實(shí)現(xiàn)strcpy函數(shù)(*出現(xiàn)次數(shù)相當(dāng)頻繁cha
4、r* strcpy(char* dest, const char* src) assert(dest != NULL) && (src != NULL); char* address = dest; while (*dest+ = *src+) != '0'); return address;char * strcpy(char * strDest,const char * strSrc) char * strDestCopy=strDest; /3 if (strDest=NULL)|(strSrc=NULL) /1 throw "Invalid a
5、rgument(s)" /2 while (*strDest+=*strSrc+)!='0'); /4 return strDestCopy; *5實(shí)現(xiàn)strcmp函數(shù)#include<iostream>#include<string>#include<assert.h>using namespace std;int strcmp(const char* str1, const char* str2) assert(str1 != NULL) && (str2 != NULL); int ret = 0; /*
6、60; 轉(zhuǎn)化為unsigned char 是為了防止溢出 例如(char)0x7f-(char)0x80=255, (unsigned char)0x7f-(unsigned char)0x80=-1*/ while (!(ret = *(unsigned char*)str1 - *(unsigned char*)str2) && *str2 !='0' && *str1 != '0') str1+; str2+; if (ret > 0) ret = 1; el
7、se if (ret < 0) ret = -1; return ret;int main(void)cout<<strcmp("abd","abce")<<endl;return 0;*6 string類的編寫(xiě)#include<iostream>using namespace std;class Stringpublic :String(const char *str = NULL);/普通構(gòu)造函數(shù)String(const String &other);/拷貝構(gòu)造函數(shù)String(void);/析構(gòu)函數(shù)
8、String &operator=(const String &other); /賦值函數(shù)String &operate+(const String &s1, const String &s2);/加法函數(shù) private:char *m_data;/普通構(gòu)造函數(shù)String:String(const char *str)if (str = NULL)m_data = new char1;*m_data = '0'elseint lenth = strlen(str);m_data = new charlenth+1;strcpy(m_d
9、ata, str);/拷貝構(gòu)造函數(shù)String:String(const String &other)int lenth = strlen(other.m_data);m_data = new charlenth+1;strcpy(m_data, other.m_data);/析構(gòu)函數(shù)String:String()delete m_data;/賦值函數(shù)String & String:operator=(const String &other)/檢查自賦值if(this = &other)return *this;/釋放原有資源delete m_data;/分配新
10、的內(nèi)存資源,并賦值int len = strlen(otehr.m_data);m_data = new charlen+1;strcpy(m_data, other.m_data);/返回本對(duì)象的引用return *this;/加法函數(shù)String &operator+( const String &s1, const String &s2)String temp;delete temp.data;/ temp.data是僅含0的字符串temp.data = new charstrlen(s1.data) + strlen(s2.data) +1;strcpy(tem
11、p.data, s1.data);/data為char *型的數(shù)據(jù)成員。strcat(temp.data, s2.data);return temp;/便于理解上述代碼,寫(xiě)出main函數(shù)int main(void) String str_a = new String();/調(diào)用構(gòu)造函數(shù)String str_b = new String(“abc”); String str_c = str_b;/調(diào)用拷貝構(gòu)造函數(shù) str_c = str_a;/賦值 String srt_d; str_d =str_c + str_b;7. 寫(xiě)出在母串中查找子串出現(xiàn)次數(shù)的代碼。 思路:從第一個(gè)字符開(kāi)始查找,然后逐
12、個(gè)比較兩個(gè)字符串是否相同,直到子字符串結(jié)束都相同則表明找到一次,num+1,然后第二個(gè)字符開(kāi)始。重復(fù)int count(char* str,char* substr) char* str1; char* str2; int num = 0; while(*str!='0') str1 = str; str2 = substr; while(*str2=*str1&&(*str2!='0')&&(*str1!='0') str2+; str1+; if(*str2 = '0') num+; str+;
13、 return num; *8.寫(xiě)函數(shù)完成內(nèi)存的拷貝一個(gè)內(nèi)存拷貝函數(shù)的實(shí)現(xiàn)體void *memcpy(void *pvTo,const void *pvFrom,size_t size)assert(pvTo!=NULL)&&(pvFrom!=NULL);byte *pbTo=(byte*)pvTo; /防止地址被改變byte *pbFrom=(byte*)pvFrom;while (size- > 0)*pbTo+ = *pbForm+;return pvTo;*9.將一個(gè)數(shù)字字符串轉(zhuǎn)換為數(shù)字."1234" ->1234i nclude<
14、iostream>using namespace std;int f(char* s) int k = 0; while (*s != 0) k = 10 * k + (*s+)- '0' /k每乘以1次10,則位數(shù)左移一位(如個(gè)位變成10位) return k;int main() int digit = f("4567"); cout<<digit<<endl; cin.get();10. 求1000!的末尾有幾個(gè)0 (用素?cái)?shù)相乘的方法來(lái)做,如72=2*2*2*3*3);求出1->1000里,能被5整除的數(shù)的個(gè)數(shù)n1,
15、能被25整除的數(shù)的個(gè)數(shù)n2,能被125整除的數(shù)的個(gè)數(shù)n3,能被625整除的數(shù)的個(gè)數(shù)n4.1000!末尾的零的個(gè)數(shù)=n1+n2+n3+n4; #include<stdio.h> #define NUM 1000 int find5(int num) int ret=0; while(num%5=0) num/=5; ret+; return ret; int main() int result=0; int i; for(i=5;i<=NUM;i+=5) result+=find5(i); printf(" the total zero number is %dn&q
16、uot;,result); return 0; 11. 寫(xiě)一個(gè)函數(shù)找出一個(gè)整數(shù)數(shù)組中,第二大的數(shù) 。 const int MINNUMBER = -32767 ; int find_sec_max( int data , int count) int maxnumber = data0 ; int sec_max = MINNUMBER ; for ( int i = 1 ; i < count ; i+) if ( datai > maxnumber ) sec_max = maxnumber ; maxnumber = datai ; else if ( datai >
17、sec_max ) sec_max = datai ; return sec_max ;12. 用遞歸算法判斷數(shù)組aN是否為一個(gè)遞增數(shù)組。 遞歸的方法,記錄當(dāng)前最大的,并且判斷當(dāng)前的是否比這個(gè)還大,大則繼續(xù),否則返回false結(jié)束: bool fun( int a, int n ) if( n= =1 ) return true; if( n= =2 ) return an-1 >= an-2; return fun( a,n-1) && ( an-1 >= an-2 ); /遞歸的同時(shí)要保證上一次的條件成立13. 選擇排序算法思想簡(jiǎn)單描述:在要排序的一組數(shù)中,選出
18、最小的一個(gè)數(shù)與第一個(gè)位置的數(shù)交換;然后在剩下的數(shù)當(dāng)中再找最小的與第二個(gè)位置的數(shù)交換,如此循環(huán)到倒數(shù)第二個(gè)數(shù)和最后一個(gè)數(shù)比較為止。 選擇排序是不穩(wěn)定的。算法復(fù)雜度O(n2)-n的平方【外層循環(huán)n-1趟,內(nèi)層(第i+1趟)循環(huán)n-i-1次】【對(duì)比冒泡排序:外層循環(huán)n-1趟,內(nèi)層(第i趟)循環(huán)n-i-1次】void select_sort(int *x, int n) int i, j, min, t; for (i=0; i<n-1; i+) /*要選擇的次數(shù):共n-1次*/ min = i; /*假設(shè)當(dāng)前下標(biāo)為i的數(shù)最?。◤?開(kāi)始,逐步加1),比較后再調(diào)整*/ for (j=i+1; j&
19、lt;n; j+)/*循環(huán)找出最小的數(shù)的下標(biāo)是哪個(gè)*/ if (*(x+j) < *(x+min) min = j; /*如果后面的數(shù)比前面的小,則記下它的下標(biāo)*/ if (min != i) /*如果min在循環(huán)中改變了,就需要交換數(shù)據(jù)*/ t = *(x+i); *(x+i) = *(x+min); *(x+min) = t; 14直接插入排序算法思想簡(jiǎn)單描述: 在要排序的一組數(shù)中,假設(shè)前面(n-1) n>=2 個(gè)數(shù)已經(jīng)是排好順序的,現(xiàn)在要把第n個(gè)數(shù)插到前面的有序數(shù)中,使得這n個(gè)數(shù)也是排好順序的。如此反復(fù)循環(huán),直到全部排好順序。 直接插入排序是穩(wěn)定的。算法時(shí)間復(fù)雜度O(n2)-
20、n的平方【直接插入,冒泡,選擇排序的時(shí)間復(fù)雜度一樣】void insert_sort(int *x, int n)int i, j, t; for (i=1; i<n; i+) /*要選擇的次數(shù):1n共n-1次/*暫存下標(biāo)為i的數(shù)。注意:下標(biāo)從1開(kāi)始,原因就是開(kāi)始時(shí), 第一個(gè)數(shù)即下標(biāo)為0的數(shù),前面沒(méi)有任何數(shù),單單一個(gè),認(rèn)為它是排好順序的,方便下面的for循環(huán)下標(biāo)的書(shū)寫(xiě)。*/ t=*(x+i); for (j=i-1; j>=0 && t<*(x+j); j-) /*注意:j=i-1,j-,這里就是在下標(biāo)為i的數(shù)后面有序列中找插入位置?!具@里的后面指的是右邊】*
21、/*(x+j+1) = *(x+j); /*如果滿足條件就往后挪。最壞的情況就是t比下標(biāo)為0的數(shù)都小,它要放在最前面,j=-1,退出循環(huán)*/ *(x+j) = t; /*找到下標(biāo)為i的數(shù)的放置位置【改變參考點(diǎn)】*/看到這里15冒泡排序16. 文件中有一組整數(shù),要求排序后輸出到另一個(gè)文件中。 #include<iostream> #include<fstream> using namespace std; void Order(vector<int>& data) /bubble sort int count = data.size() ; int t
22、ag = false ; / 設(shè)置是否需要繼續(xù)冒泡的標(biāo)志位 for ( int i = 0 ; i < count ; i+) for ( int j = 0 ; j < count - i - 1 ; j+) if ( dataj > dataj+1) tag = true ; int temp = dataj ; dataj = dataj+1 ; dataj+1 = temp ; if ( !tag ) break ; int main( void ) vector<int>data; ifstream in("c:data.txt");
23、 if ( !in) cout<<"file error!" exit(1); int temp; while (!in.eof() cin>>temp; data.push_back(temp); in.close(); /關(guān)閉輸入文件流 Order(data); ofstream out("c:result.txt"); if ( !out) cout<<"file error!" exit(1); for ( i = 0 ; i < data.size() ; i+) out<&l
24、t;datai<<" " out.close(); /關(guān)閉輸出文件流 17. 輸入一個(gè)字符串,將其逆序后輸出。(使用C+,不建議用偽碼) #include <iostream> using namespace std; void main() char a50;memset(a,0,sizeof(a); int i=0,j; char t; cin.getline(a,50,'n'); for(i=0,j=strlen(a)-1;i <strlen(a)/2;i+,j-) t=ai; ai=aj; aj=t; cout <
25、 <a < <endl; 18.鏈表題1)編程實(shí)現(xiàn)一個(gè)單鏈表的建立。#include<iostream>#include<stdio.h>#include<string.h>#include<conio.h>using namespace std;typedef struct studentint data;struct student *next;node;node * Create(void)node *head = NULL;node *p = NULL;node *s = NULL;int x,cycle = 1;hea
26、d = (node *)malloc (sizeof (node);p = head;printf("please int put the data: ");scanf("%d", &x);p -> data = x;p ->next = NULL;while(cycle)printf("please int put the data: ");scanf("%d", &x);if(x != 0)s = (node *)malloc(sizeof (node);s ->data =
27、x;printf("n %d", s->data);p -> next = s;p = s;else cycle = 0;p -> next = NULL;printf("n yyy %d", head -> data);return head;int main(void)Create();return 0;2)實(shí)現(xiàn)單鏈表的測(cè)長(zhǎng)雙鏈表的測(cè)長(zhǎng)也是一樣int CaculateLenth(struct student *head)struct student *p = NULL;p = head;int n = 0;while(p !=
28、 NULL)n+;p = p->next;return n;3)編程實(shí)現(xiàn)單鏈表的打印雙鏈表也是一樣的void Show(struct student *head)struct student *p = NULL;p = head;int n = 0;while(p != NULL)cout<<p->data<<endl;p = p -> next;4)編程實(shí)現(xiàn)單鏈表刪除節(jié)點(diǎn)解題思路:先遍歷比較值,找到要?jiǎng)h除節(jié)點(diǎn)后再判斷是否為頭節(jié)點(diǎn),還是后面的節(jié)點(diǎn)【刪除中間的節(jié)點(diǎn)和刪除末尾的節(jié)點(diǎn)是一個(gè)樣的】。node *Delete(struct student *he
29、ad, int num)struct student *p1 = NULL;struct student *p2 = NULL;p1 = head;while (num != p1->data && p1->next != NULL)p2 = p1;p1 = p1 ->next;if(num = p1 -> data)if(p1 = head)/刪除的是頭節(jié)點(diǎn)head = p1 -> next;free(head);else/刪除的是頭結(jié)點(diǎn)后面的節(jié)點(diǎn)p2 -> next = p1->next;free(p1);elsecout<&
30、lt;"the num hasn't been found"<<endl;return head;5)編程實(shí)現(xiàn)單鏈表的插入解析:如果插入在節(jié)點(diǎn)以前,則p0的next指向p1,投節(jié)點(diǎn)指向p0,如下圖所示如果插入尾節(jié)點(diǎn),如下圖所示。解題思路:先遍歷對(duì)比關(guān)鍵值,找到后再判斷在第一個(gè)節(jié)點(diǎn)前插入還是中間插入還是最后面插入。node *Insert(node *head, int num)node *p0, *p1, *p2;p1 = head;p0 = (node *)malloc(sizeof(node);p0->data = num;while(p0 -
31、> data > p1 ->data && p1 -> next != NULL)p2 = p1;p1 = p1 -> next;if(p0 ->data <= p1 -> data)if(head = p1)/在第一個(gè)節(jié)點(diǎn)前插入p0 ->next = p1;head = p0;else/第一個(gè)節(jié)點(diǎn)以后插入,但是不在末尾插入p2->next = p0;p0 ->next = p1;else/尾部插入p1->next = p0;p0->next = NULL;return head;6)編程實(shí)現(xiàn)單鏈表的
32、逆轉(zhuǎn)。解析:?jiǎn)捂湵砟P腿缦拢哼M(jìn)行單鏈表逆轉(zhuǎn),首先要讓p2的next指針指向p1,然后重復(fù)p2的next指向p1,p1指向p2,p2指向p3node *Reverse(node *head)node *p1 = NULL;node *p2 = NULL;node *p3 = NULL;if(head = NULL && head ->next = NULL)return head;p1 = head;p2 = p1 -> next;while(p2 != NULL)p3 = p2->next; /保存第三個(gè)節(jié)點(diǎn)的地址,防止丟失p2 -> next = p1
33、;/使第二個(gè)節(jié)點(diǎn)指向第一個(gè)節(jié)點(diǎn)p1 = p2;/節(jié)點(diǎn)后推,把第二個(gè)節(jié)點(diǎn)作為第一個(gè)節(jié)點(diǎn)p2 =p3;/節(jié)點(diǎn)后推,把第三個(gè)節(jié)點(diǎn)作為第二個(gè)節(jié)點(diǎn)head -> next = NULL;/把第一個(gè)節(jié)點(diǎn)作為尾節(jié)點(diǎn)head = p1;return head;19. 怎么樣將整數(shù)轉(zhuǎn)化為字符串?dāng)?shù),并且不用函數(shù)itoa。解析:將整數(shù)轉(zhuǎn)化為字符串,可以采用加0的,再逆序的辦法,整數(shù)加0就會(huì)隱式轉(zhuǎn)化成char類型的數(shù)。#include<iostream>#include<stdio.h>int main(void)int num = 12345;int j = 0; int i = 0;
34、char temp7, str7;/itoa(number, string, 10);/假如可以使用itoa函數(shù)則十分容易(int to alpha)while(num != 0)tempi = num % 10 + 0;/獲取個(gè)位上的數(shù)字i+;num = num / 10;/為了獲取下一個(gè)個(gè)位上的數(shù)字(即把每個(gè)位上的數(shù)字降一位)做tempi = 0;/最后一個(gè)位 printf(“temp = &sn”, temp);i = i-1;printf(“temp = %dn”, i);/剛剛轉(zhuǎn)化的字符串時(shí)逆序的,必須把它反轉(zhuǎn)過(guò)來(lái)。while(i >= 0)strj = tempi;j
35、+;i-;strj = 0;printf(“string = %sn”, str);return 0;輸入一個(gè)數(shù),測(cè)試其是否是回文數(shù)。解析:建立數(shù)組,按位存儲(chǔ),比較首位和末位是否相同。如不同,則不是回文數(shù)。相同則繼續(xù)比較,首位遞增,末位遞減,直到首位不再小于末位。#include<iostream>using namespace std;int main(void)int j = 10, k = 12321, p;int a10, ss, i = 0, begin, end;cout << ”please input ” << endl;cin >&g
36、t; k;p = k;while( p != 0)ss = p % 10;ai = ss;p = p/10;i+;begin = 0;end = i-1;while(begin < end) if(abegin != aend)break;elsebegin+;end-;if(begin < end)cout<<”jiade” << endl;elsecout << “zhende” << endl;cout << “i” << i << endl;cout << k;return 0;
37、將字符串a(chǎn)skdaskaskdaskg刪除指定的字符串a(chǎn)sk,刪除后結(jié)果是”ddg”。解析:刪除的最好辦法就是把不刪除的東西提取出來(lái)。#include<stdio.h>#include<string.h>#include<conio.h>int main(void)char ch20, *p = NULL, *sub = “ask”, *str = “askdaskaskdaskg”, *str2 = NULL;int n = 0, i = 0, v;p = sub;str2 = str;while(*str2 != 0)while(*p = 0)if(*p
38、 = *str2)break;p+;If(*p != 0)chi = *str2;i+;str2+;p = sub;chi = 0;str = ch;printf(“n %s”, str);return 0;請(qǐng)寫(xiě)出一個(gè)函數(shù)來(lái)模擬C+中的strstr函數(shù):該函數(shù)的返回值是主串中字符子串的位置以后的所有字符。請(qǐng)不要使用任何C程序已有的函數(shù)來(lái)完成。const char *strstr(const char *string, const char *strCharSet)解析:函數(shù)是主把主串中子串及以后的字符全部返回。比如主串“12345678”,字串是234,那么返回值就是2345678#inclu
39、de<iostream>using namespace std;const char *strstr(const char *string, congest char *strCharSet)for(int i=0; stringi != 0; i+)int j = 0;int temp = i;if(stringi = strCharSetj) while(stringi+ =strCharSetj+) if(strCharSeti = 0)return &stringi-ji = temp;return NULL;int main(void)char *string =
40、 “12345554555123”;cout<<string<<endl;char strCharSet10 = ;cin strCharSet;cout<<strstr(string, strCharSet)<<endl;return 0;將一句話里的單詞進(jìn)行倒置,標(biāo)點(diǎn)符號(hào)不能倒換,比如一句話“I come from tianjin.”à“tianjin from come i”解析:解決該問(wèn)題可以分成兩步,第一步全盤(pán)置換將該語(yǔ)句變成“.nijnait morf emoc i”,第二步進(jìn)行部分翻轉(zhuǎn),如果不是空格,則開(kāi)始翻轉(zhuǎn)單詞。#in
41、clude<iostream>#include<stdio.h>int main(void)int num = -12345, j = 0, i = 0,flag = 0, begin, end;char str = “i come from tianjin.”, temp;j = strlen(str)-1;printf(“string = %sn“, str);/第一步:進(jìn)行全盤(pán)翻轉(zhuǎn),將單詞變成“nijnait morf emoc i”while(j > i)/strj = tempi;temp = stri;stri = strj;strj = temp;j
42、-;i+;printf(“string = %sn”, str);i = 0;/第二步,進(jìn)行部分翻轉(zhuǎn),如果不是空格,則開(kāi)始翻轉(zhuǎn)單詞隊(duì)列1) 編程實(shí)現(xiàn)隊(duì)列的入隊(duì)3. 一個(gè)射擊運(yùn)動(dòng)員打靶,靶一共有10環(huán),連開(kāi)10槍,打中90環(huán)的可能性有多少種?請(qǐng)用遞歸算法編程實(shí)現(xiàn)。?n21 2220 7 8 9 1019 6 1 2 1118 5 4 3 1217 16 15 14 13可以看清楚上面排序的規(guī)律,設(shè)1點(diǎn)的坐標(biāo)為(0,0);x向右為正,向左為負(fù),y方向向上為正,向下為負(fù),如7的坐標(biāo)是(-1,-1);2的坐標(biāo)為(0,1);3的坐標(biāo)為(1,1);編程實(shí)現(xiàn)任意一點(diǎn)的坐標(biāo)為(1,1);編程實(shí)現(xiàn)任意一點(diǎn)的坐標(biāo)
43、(x,y),輸出對(duì)應(yīng)的數(shù)字#include<stdio.h>int main(void) int x, y; for ( y=-4; y<5; y+) for (x=-4; x<5; x+) printf(“%5d”, foo(x,y); printf(“n”);?3.unsigned int intvert(unsigned int x,int p,int n)實(shí)現(xiàn)對(duì)x的進(jìn)行轉(zhuǎn)換,p為起始轉(zhuǎn)化位,n為需要轉(zhuǎn)換的長(zhǎng)度,假設(shè)起始點(diǎn)在右邊.如x=0b0001 0001,p=4,n=3轉(zhuǎn)換后x=0b0110 0001unsigned int intvert(unsigned
44、int x,int p,int n)unsigned int _t = 0;unsigned int _a = 1;for(int i = 0; i < n; +i)_t |= _a;_a = _a << 1;_t = _t << p;x = _t;return x;6)寫(xiě)出查找從一個(gè)集合中輸出所有子集合的算法. . ?9. 查找第一個(gè)匹配子串位置,如果返回的是str1長(zhǎng)度len1表示沒(méi)有找到。 size_t find(char* str1,char* str2) size_t i=0; size_t len1 = strlen(str1) size_t len2
45、 = strlen(str2); /要查找的子串比母串長(zhǎng) if(len1-len2<0) return len1; for(;i<len1-len2;i+) size_t m = i; size_t j=0 for(;size_t j=0;j<len2;j+) if(str1m!=str2j) break; m+; if(j=len) break; return i<len1-len2?i:len1; ?24 寫(xiě)一個(gè)函數(shù),它的原形是int continumax(char *outputstr,char *intputstr)。 功能: 在字符串中找出連續(xù)最長(zhǎng)的數(shù)字串,并
46、把這個(gè)串的長(zhǎng)度返回,并把這個(gè)最長(zhǎng)數(shù)字串付給其中一個(gè)函數(shù)參數(shù)outputstr所指內(nèi)存。例如:"abcd12345ed125ss123456789"的首地址傳給intputstr后,函數(shù)將返回9,outputstr所指的值為123456789 int continumax(char *outputstr, char *inputstr) char *in = inputstr, *out = outputstr, *temp, *final; int count = 0, maxlen = 0; while( *in != '0' ) if( *in >
47、 47 && *in < 58 ) for(temp = in; *in > 47 && *in < 58 ; in+ ) count+; else in+; if( maxlen < count ) maxlen = count; count = 0; final = temp; for(int i = 0; i < maxlen; i+) *out = *final; out+; final+; *out = '0' return maxlen; 7.用戶輸入M,N值,從1至N開(kāi)始順序循環(huán)數(shù)數(shù),每數(shù)到M輸出該數(shù)值
48、,直至全部輸出。寫(xiě)出C程序。循環(huán)鏈表,用取余操作做*4)寫(xiě)出快速排序或者某種排序算法代碼?出現(xiàn)次數(shù)相當(dāng)頻繁5)寫(xiě)出查找從一個(gè)集合中輸出所有子集合的算法.?9)循環(huán)鏈表的節(jié)點(diǎn)對(duì)換和刪除。11)實(shí)現(xiàn)任意長(zhǎng)度的整數(shù)相加或者相乘功能。?3)客房預(yù)定的問(wèn)題.根據(jù)客戶報(bào)的人數(shù),客房等級(jí)來(lái)從預(yù)備的客房中選擇出所有符合要求的 客房號(hào).客戶沒(méi)有要求等級(jí)時(shí),只考慮人數(shù)因素就可以了.要考慮有些客房已經(jīng)預(yù)定的情況. (寫(xiě)代碼是要考慮好彼此的效率) 6)在文件(調(diào)用庫(kù)函數(shù)創(chuàng)建的,不用考慮數(shù)據(jù)庫(kù)的方式)中讀入信息(包括職工號(hào),職工產(chǎn)量) .根據(jù)輸入的信息(包括職工號(hào),職工產(chǎn)量).檢測(cè)是否有相同的職工號(hào)記錄,如有,則增加其
49、 產(chǎn)量.如沒(méi)有,則創(chuàng)建新的記錄.最后的記錄排序的依據(jù)是職工產(chǎn)量(降序),如果產(chǎn)量相同,則 按職工號(hào)(升序). 2.面試 1)找出兩個(gè)中文句子的相似度.(例如"中國(guó)江蘇南京" "江蘇省中國(guó)南京市".實(shí)際上是指的同一個(gè)地方.面試官的要求是一分鐘給出求相似度的算法.)(幸好聽(tīng)老師講過(guò)中文分詞,要不 然當(dāng)場(chǎng)就掛了) 4)寫(xiě)出在母串中查找子串出現(xiàn)次數(shù)的代碼. 24. unsigned short hash(unsigned short key) return (key>>)%256 請(qǐng)問(wèn)hash(16),hash(256)的值分別是: A.1.16;B
50、.8.32;C.4.16;D.1.3219.typedef unsigned char BYTE int examply_fun(BYTE gt_len; BYTE *gt_code) BYTE *gt_buf; gt_buf=(BYTE *)MALLOC(Max_GT_Length); . if(gt_len>Max_GT_Length) return GT_Length_ERROR; . : 20.TCP/IP通信建立的過(guò)程怎樣,端口有什么作用? 三次握手,確定是哪個(gè)應(yīng)用程序使用該協(xié)議 3Windows下的內(nèi)存是如何管理的?4介紹.Net和.Net的安全性。5客戶端如何訪問(wèn).Net組
51、件實(shí)現(xiàn)Web Service?7談?wù)凜OM的線程模型。然后討論進(jìn)程內(nèi)/外組件的差別。?8Apartment在COM中有什么用?為什么要引入?9談?wù)刉indows DNA結(jié)構(gòu)的特點(diǎn)和優(yōu)點(diǎn)。2.數(shù)組aN,存放了1至N-1個(gè)數(shù),其中某個(gè)數(shù)重復(fù)一次。寫(xiě)一個(gè)函數(shù),找出被重復(fù)的數(shù)字.時(shí)間復(fù)雜度必須為o(N)函數(shù)原型:int do_dup(int a,int N)int strlen(const char* str) assert(str != NULL); int len = 0; while ('0' != *str+) len+; return len;編程計(jì)算從鍵盤(pán)上輸入單詞個(gè)數(shù),并從中找出最多字符的
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 砌磚抹灰勞務(wù)合同
- 事業(yè)單位職工勞動(dòng)合同
- 廠房建筑施工合同
- 軟件合作開(kāi)發(fā)協(xié)議書(shū)8篇
- 第三單元巖石與土壤 教學(xué)設(shè)計(jì)-2023-2024學(xué)年科學(xué)四年級(jí)下冊(cè)教科版
- 第四章第三節(jié) 工業(yè)同步教學(xué)設(shè)計(jì)2023-2024學(xué)年八年級(jí)上冊(cè)地理 人教版
- 格賓加筋土邊坡施工方案
- 二米六鈦金條門(mén)施工方案
- 2025新版工程裝修合同8篇
- 專題節(jié)目許可使用協(xié)議范本7篇
- 《服裝品牌策劃》課件
- 近五年陜西中考數(shù)學(xué)真題及答案2024
- 美國(guó)藥典-USP-561-植物源性物質(zhì)
- 0-3歲嬰幼兒基礎(chǔ)護(hù)理知到智慧樹(shù)章節(jié)測(cè)試課后答案2024年秋杭州師范大學(xué)
- 掛靠免責(zé)協(xié)議書(shū)范本
- 2024-2030年中國(guó)新媒體市場(chǎng)前景規(guī)模及發(fā)展趨勢(shì)分析報(bào)告
- Python金融數(shù)據(jù)分析與挖掘(微課版) 教案全套 黃恒秋
- 《銷售人員的培訓(xùn)》課件
- 國(guó)防動(dòng)員課件教學(xué)課件
- 特殊作業(yè)安全管理監(jiān)護(hù)人專項(xiàng)培訓(xùn)課件
- 自行車被盜案匯報(bào)課件
評(píng)論
0/150
提交評(píng)論