




已閱讀5頁,還剩23頁未讀, 繼續免費閱讀
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
2012華為校園招聘機考試題總結(廈門大學)1、刪除子串,只要是原串中有相同的子串就刪掉,不管有多少個,返回子串個數。#include #include #include #include int delete_sub_str(const char *str,const char *sub_str,char *result)assert(str != NULL & sub_str != NULL);const char *p,*q;char *t,*temp;p = str;q = sub_str;t = result;int n,count = 0;n = strlen(q);tmep = (char *)malloc(n+1);memset(temp,0x00,n+1);while(*p)memcpy(temp,p,n);if(strcmp(temp,q) = 0 )count+;memset(temp;0x00,n+1);p = p + n;else*t = *p;p+;t+;memset(temp,0x00,n+1);free(temp);return count;int main()char s100 = 0;int num = delete_sub_str(“123abc12de234fg1hi34j123k”,”123”,s);printf(“The number of sub_str is %drn”,num);printf(“The result string is %srn”,s);2、約瑟夫環是一個數學的應用問題:已知n個人(以編號1,2,3.n分別表示)圍坐在一張圓桌周圍。從編號為k的人開始報數,數到m的那個人出列;他的下一個人又從1開始報數,數到m的那個人又出列;依此規律重復下去,直到圓桌周圍的人全部出列。#include#includetypedef struct Nodeint num;struct Node *next;LinkList;LinkList *creat(int n)LinkList *p,*q,*head;int i=1; p=(LinkList *)malloc(sizeof(LinkList); p-num=i;head=p; for(i=2;inum=i; p-next=q; p=q; p-next=head; /*使鏈表尾指向鏈表頭 形成循環鏈表*/ return head;void fun(LinkList *L,int m)int i;LinkList *p,*s,*q;p=L;printf(出列順序為:);while(p-next!=p)for(i=1;inext;printf(%5d,p-num);s=p;q-next=p-next;p=p-next;free(s);printf(%5dn,p-num);int main()LinkList *L;int n, m;n=9;m=5;L=creat(n);fun(L,m);return 0;3、比較一個數組的元素是否為回文數組#include #include int huiwen(char str)int i,len,k=1;len=strlen(str);for(i=0;ilen/2;i+)if(stri!=strlen-i-1)k=1;break;if(k=0) printf(%s 不是一個回文數n,str);elseprintf(%s 是一個回文數n,str);void main() char str100 = 0; int i;int len;printf(Input a string:); /*提示輸入Input a string:*/scanf(%s, str); /*scan()函數輸入一個字符串:*/huiwen(str);4、數組比較(20分) 問題描述:比較兩個數組,要求從數組最后一個元素開始逐個元素向前比較,如果2個數組長度不等,則只比較較短長度數組個數元素。請編程實現上述比較,并返回比較中發現的不相等元素的個數比如:數組1,3,5和數組77,21,1,3,5按題述要求比較,不相等元素個數為0數組1,3,5和數組77,21,1,3,5,7按題述要求比較,不相等元素個數為3 要求實現函數:intarray_compare(intlen1,intarray1,intlen2,intarray2)【輸入】 intlen1:輸入被比較數組1的元素個數;intarray1:輸入被比較數組1;intlen2:輸入被比較數組2的元素個數;intarray2:輸入被比較數組2;【輸出】 無【返回】 不相等元素的個數,類型為int 示例1) 輸入:intarray1=1,3,5,intlen1=3,intarray2=77,21,1,3,5,intlen2=5函數返回:02) 輸入:intarray1=1,3,5,intlen1=3,intarray2=77,21,1,3,5,7,intlen2=6函數返回:#include#include#includeint array_compare(int len1, int array1, int len2, int array2)int count=0;for( ;len1=0&len2=0 ;len1-,len2-)if(array1len1-1=array2len2-1) count+;return count;int main()int result=0;int array1=1,3,5;int len1=3;int array2=77,12,1,3,5;int len2=5;result=array_compare( len1, array1, len2, array2); /result=array_compare( len1, array1, len2, array2);不能這樣 / 函數形參中永遠只是傳得首地址,不能傳數組 切記切記!printf(the result is %d, result);5、約瑟夫問題 問題描述:輸入一個由隨機數組成的數列(數列中每個數均是大于0的整數,長度已知),和初始計數值m。從數列首位置開始計數,計數到m后,將數列該位置數值替換計數值m,并將數列該位置數值出列,然后從下一位置從新開始計數,直到數列所有數值出列為止。如果計數到達數列尾段,則返回數列首位置繼續計數。請編程實現上述計數過程,同時輸出數值出列的順序比如: 輸入的隨機數列為:3,1,2,4,初始計數值m=7,從數列首位置開始計數(數值3所在位置)第一輪計數出列數字為2,計數值更新m=2,出列后數列為3,1,4,從數值4所在位置從新開始計數第二輪計數出列數字為3,計數值更新m=3,出列后數列為1,4,從數值1所在位置開始計數第三輪計數出列數字為1,計數值更新m=1,出列后數列為4,從數值4所在位置開始計數最后一輪計數出列數字為4,計數過程完成。輸出數值出列順序為:2,3,1,4。 要求實現函數:voidarray_iterate(intlen,intinput_array,intm,intoutput_array)【輸入】 intlen:輸入數列的長度;intintput_array:輸入的初始數列intm:初始計數值【輸出】 intoutput_array:輸出的數值出列順序【返回】 無 示例輸入:intinput_array=3,1,2,4,intlen=4,m=7輸出:output_array=2,3,1,4/循環鏈表實現/#include#include#includetypedef struct Nodeint num;struct node *next; node;node *creat(int len , int input_array)node *h,*s,*p;int i;h=(node*)malloc(sizeof(node);h-num=input_array0;p=h;for(i=1;inum=input_arrayi; p-next=s; p=s; p-next=h; return (h);void array_iterate(int len, int input_array, int m)node *q,*p,*s;int i=0,j=0,k;int output_array4;p=creat(len,input_array);while(p-next!=p)for(i=1;inext;m=p-num; printf(%5d,m);output_arrayj+=m;s=p;q-next=p-next;p=p-next;free(s);s=NULL;m=p-num; printf(%5dn,m);output_arrayj=p-num;k=j;for(j=0 ; j=k; j+)printf(%5d,output_arrayj);int main()int input_array=3,1,2,4;int len=4;int m=7;int output_array4;array_iterate(len, input_array, m, output_array);6、 手機號碼合法性判斷(20分)l 問題描述:我國大陸運營商的手機號碼標準格式為:國家碼+手機號碼,例如:8613912345678。特點如下:1、 長度13位;2、 以86的國家碼打頭;3、 手機號碼的每一位都是數字。 請實現手機號碼合法性判斷的函數要求:1) 如果手機號碼合法,返回0;2) 如果手機號碼長度不合法,返回13) 如果手機號碼中包含非數字的字符,返回2;4) 如果手機號碼不是以86打頭的,返回3;【注】除成功的情況外,以上其他合法性判斷的優先級依次降低。也就是說,如果判斷出長度不合法,直接返回1即可,不需要再做其他合法性判斷。l 要求實現函數:int verifyMsisdn(char* inMsisdn)【輸入】 char* inMsisdn,表示輸入的手機號碼字符串。【輸出】 無【返回】 判斷的結果,類型為int。l 示例輸入: inMsisdn = “869123456789“輸出: 無返回: 1輸入: inMsisdn = “88139123456789“輸出: 無返回: 3輸入: inMsisdn = “86139123456789“輸出: 無返回: 0#include#include#include#include#define LENGTH 13int verifyMsisdn(char *inMsisdn)char *pchar=NULL;assert(inMsisdn!=NULL);if(LENGTH=strlen(inMsisdn)if(8=*inMsisdn)&(*(inMsisdn+1)=6)while(*inMsisdn!=0)if(*inMsisdn=0)&(*inMsisdn=9)inMsisdn+;else return 2 ;elsereturn 3;elsereturn 1;return 0;int main()char *pchar=NULL;unsigned char ichar=0;int result;switch(ichar)case 0:pchar=8612345363789;break;case 1:pchar=861111111111111;break;case 2:pchar=86s1234536366; break;default: break; result =verifyMsisdn(pchar); printf(result is %dn,result);7、數組比較(20分) 問題描述:比較兩個數組,要求從數組最后一個元素開始逐個元素向前比較,如果2個數組長度不等,則只比較較短長度數組個數元素。請編程實現上述比較,并返回比較中發現的不相等元素的個數比如:數組1,3,5和數組77,21,1,3,5按題述要求比較,不相等元素個數為0數組1,3,5和數組77,21,1,3,5,7按題述要求比較,不相等元素個數為3 要求實現函數:intarray_compare(intlen1,intarray1,intlen2,intarray2)【輸入】 intlen1:輸入被比較數組1的元素個數;intarray1:輸入被比較數組1;intlen2:輸入被比較數組2的元素個數;intarray2:輸入被比較數組2;【輸出】 無【返回】 不相等元素的個數,類型為int 示例1) 輸入:intarray1=1,3,5,intlen1=3,intarray2=77,21,1,3,5,intlen2=5函數返回:02) 輸入:intarray1=1,3,5,intlen1=3,intarray2=77,21,1,3,5,7,intlen2=6函數返回:3#include#include#includeint array_compare(int len1, int array1, int len2, int array2)int count=0;for( ;len1=0&len2=0 ;len1-,len2-)if(array1len1-1=array2len2-1) count+;return count;int main()int result=0;int array1=1,3,5;int len1=3;int array2=77,12,1,3,5;int len2=5;result=array_compare(len1, array1, len2, array2); /result=array_compare( len1, array1, len2, array2);不能這樣/ 函數形參中永遠只是傳得首地址,不能傳數組 切記切記!printf(the result is %d, result);8、簡單四則運算 問題描述:輸入一個只包含個位數字的簡單四則運算表達式字符串,計算該表達式的值注: 1、表達式只含+,-,*,/四則運算符,不含括號2、表達式數值只包含個位整數(0-9),且不會出現0作為除數的情況3、要考慮加減乘除按通常四則運算規定的計算優先級4、除法用整數除法,即僅保留除法運算結果的整數部分。比如8/3=2。輸入表達式保證無0作為除數情況發生5、輸入字符串一定是符合題意合法的表達式,其中只包括數字字符和四則運算符字符,除此之外不含其它任何字符,不會出現計算溢出情況 要求實現函數:intcalculate(intlen,char*expStr)【輸入】 intlen:字符串長度;char*expStr:表達式字符串;【輸出】 無【返回】 計算結果 示例1) 輸入:char*expStr=“1+4*5-8/3”函數返回:192) 輸入:char*expStr=“8/3*3”函數返回:6 #include /* * author by wanww * time: 2011-09-07 */using namespace std;int array_compare(int len1, int array1, int len2, int array2) if(len1 = len2) int count = 0;for (int i=0;ilen1;i+)if(array1i!=array2i) count+;return count; else if(len1=0 & ch = 9 )data.top+;data.numericdata.top = ch-0; else if(+ = ch)int tmp = data.numericdata.top-1 + data.numericdata.top;data.top-;data.numericdata.top = tmp;else if(- = ch)int tmp = data.numericdata.top-1 - data.numericdata.top;data.top-;data.numericdata.top = tmp;else if(* = ch)int tmp = data.numericdata.top-1 * data.numericdata.top;data.top-;data.numericdata.top = tmp;else if(/ = ch) if(data.numericdata.top = 0)printf(cannot be zero of the dividen);exit(1);int tmp = data.numericdata.top-1 / data.numericdata.top;data.top-;data.numericdata.top = tmp;i+;ch = expStri; return data.numericdata.top;void main()int array1 = 1,3,5;int len1 = 3;int array2 = 77,21,1,3,5,7;int len2 = 6;int count =array_compare(sizeof(array1)/sizeof(int),array1,sizeof(array2)/sizeof(int),array2);printf(%dn,count); printf(*n);int input_array = 3,1,2,4;int len = 4;int m=7;int * output_array = new intsizeof(input_array)/sizeof(int);array_iterate(4,input_array,7,output_array); for (int i=0;isizeof(input_array)/sizeof(int);i+)printf(%d ,output_arrayi); delete output_array;printf(n*n);char expStr = 8/3*3; int result = calculate(strlen(expStr),expStr);printf(%sn,expStr);printf(%dn,result);9、選秀節目打分,分為專家評委和大眾評委,score 數組里面存儲每個評委打的分數,judge_type 里存儲與 score 數組對應的評委類別,judge_typei = 1,表示專家評委,judge_typei = 2,表示大眾評委,n表示評委總數。打分規則如下:專家評委和大眾評委的分數先分別取一個平均分(平均分取整),然后,總分 = 專家評委平均分 *0.6 + 大眾評委 * 0.4,總分取整。如果沒有大眾評委,則 總分 = 專家評委平均分,總分取整。函數最終返回選手得分。函數接口 int cal_score(int score, int judge_type, int n)#include#include#include#include#define N 5int cal_score(int score, int judge_type, int n) int expert=0; int dazhong=0;int zongfen=0;int i;int number=0;for(i=0;iN;i+)if(judge_typei=1)expert=expert+scorei;number+;else dazhong=dazhong+scorei;if(number=N)zongfen=(int)(expert/N);else expert=(int)(expert/number);dazhong=(int)(dazhong/(N-number);zongfen=int(0.6*expert+0.4*dazhong);return zongfen;int main()int scoreN;int judge_typeN;int numberlast=0;int i;printf(please input the %d score:n,N);for(i=0;iN;i+)scanf(%d,&scorei);printf(please input the level(1:expert,2:dazhong)n);for(i=0;iN;i+)scanf(%d,&judge_typei);numberlast=cal_score(score,judge_type,N);printf(the last score is %dn,numberlast);return 0;10、給定一個數組input ,如果數組長度n為奇數,則將數組中最大的元素放到 output 數組最中間的位置,如果數組長度n為偶數,則將數組中最大的元素放到 output 數組中間兩個位置偏右的那個位置上,然后再按從大到小的順序,依次在第一個位置的兩邊,按照一左一右的順序,依次存放剩下的數。 例如:input = 3, 6, 1, 9, 7 output = 3, 7, 9, 6, 1; input = 3, 6, 1, 9, 7, 8 output =1, 6, 8, 9, 7, 3#include#include#includevoid sort(int input, int n, int output)int i,j;int k=1;int temp;int med;for(i=0;in;i+)for(j=0;jinputj+1)temp=inputj;inputj=inputj+1;inputj+1=temp;if(n%2!=0)for(i=0;in;i+)printf(%2d,inputi);printf(n);med=(n-1)/2;outputmed=inputn-1;for(i=1;i=med;i+)outputmed-i=inputn-1-k;outputmed+i=inputn-2-k;k=k+2;elsefor(i=0;in;i+)printf(%2d,inputi);printf(n);med=n/2;outputmed=inputn-1;for(i=1;i=med-1;i+)outputmed-i=inputn-1-k;outputmed+i=inputn-2-k;k=k+2;output0=input0;for(i=0;in;i+)printf(%2d,outputi);printf(n);int main()int a6=3,6,1,9,7,8;int b6=0;for(int i=0;i6;i+)printf(%2d,ai);printf(n);sort(a,6,b);return 0;11、操作系統任務調度問題。操作系統任務分為系統任務和用戶任務兩種。其中,系統任務的優先級 = 50且 = 255。優先級大于255的為非法任務,應予以剔除。現有一任務隊列task,長度為n,task中的元素值表示任務的優先級,數值越小,優先級越高。函數scheduler實現如下功能,將task 中的任務按照系統任務、用戶任務依次存放到 system_task 數組和 user_task 數組中(數組中元素的值是任務在task 數組中的下標),并且優先級高的任務排在前面,數組元素為-1表示結束。 例如:task = 0, 30, 155, 1, 80, 300, 170, 40, 99 system_task = 0, 3, 1, 7, -1 user_task = 4, 8, 2, 6, -1函數接口 void scheduler(int task, int n, int system_task, int user_task)#include#include#include#includevoid scheduler1(int task, int n, int system_task, int user_task)int i;int j=0;int *p,*pp,*p_user,*pp_user;int index=0;int count,count2;int min=0;int k=0;p=(int*)malloc(sizeof(int)*n);for(i=0;in;i+)pi=0;pp=(int*)malloc(sizeof(int)*n);for(i=0;in;i+)ppi=0;p_user=(int*)malloc(sizeof(int)*n);for(i=0;in;i+)p_useri=0;pp_user=(int*)malloc(sizeof(int)*n);for(i=0;in;i+)pp_useri=0;for(i=0;in;i+)if(taski50)system_taskj=taski;ppj=i;j+;count=j;else if(taski=255)user_taskk=taski;pp_userk=i;k+;count2=k;else taski=taski;for(i=0;icount;i+)printf(%3d,system_taski);printf(n);for(i=0;icount;i+)min=system_task0;for(j=1;jcount;j+)if(system_taskjmin)min=system_taskj;pi=j;system_taskpi=51; ppcount=-1;for(i=0;icount;i+)printf(%3d,pppi);printf(%3dn,ppcount);/*/for(i=0;icount2;i+)printf(%4d,user_taski);printf(n);for(i=0;icount2;i+)min=user_task0;for(j=1;jcount2;j+)if(user_taskjmin)min=user_taskj;p_useri=j;user_taskp_useri=256; pp_usercount2=-1;for(i=0;icount2;i+)printf(%4d,pp_userp_useri);printf(%3dn,pp_usercount2);int main()int task9=0, 30, 155, 1, 80, 300,170, 40, 99;int system_task9=0;int user_task9=0;scheduler1(task,9,system_task,user_task);return 0;12、 從兩個數組的最后一個元素比較兩個數組中不同元素的個數,如有array15=77,21,1,3,5, array23=1,3,5,從array14與array22比較開始,到array12與array0比較結束。這樣得出它們不同的元素個數為0,若array16=77,21,1,3,5,7,那么他們不同的元素為3。函數原型為 int compare_array( int len1, int array1, int len2, int array2 );其中,len1與len2分別為數組array1和array2的長度,函數返回值為兩個數組不同元素的個數。以下是上題的函數完整實現:/diff_num.cpp#includeint compare_array(int len1,int array1,int len2,int array2)int i,t,small,num=0;/把兩數組倒置for(i=0;ilen1/2;i+)t=array1i;array1i=array1len1-i-1;
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 初中語文寫作教學中的家庭參與策略研究論文
- 新時代背景下高中生傳統文化素養提升策略研究論文
- 藝術部主任管理制度
- 蘇州燃氣罐管理制度
- 茶水爐衛生管理制度
- 高校重修后管理制度
- 一年級《小青蛙》課件
- 視頻監控系統防雷方案
- 道德與法治(陜西卷)(考試版A3)
- 2025年四川省德陽市中考歷史真題試卷(含答案)
- 部編版六年級道德與法治上冊期末復習課件
- 氫能源行業的投資機會分析
- 供電公司負責人講安全課
- 【物理】《滑輪》(教學設計)-2024-2025學年人教版(2024)初中物理八年級下冊
- 火車站高鐵站消防培訓
- 專項10:現代文閱讀 媒體文閱讀(練習)-【中職專用】2025年對口升學語文二輪專項突破(解析版)
- 降低患者跌倒的發生率
- 2024中華人民共和國學前教育法詳細解讀課件
- 湖北省武漢市2024年中考數學試卷(含答案)
- 2023-2024學年山東省濰坊市高二下學期期中考試歷史試題(解析版)
- 人教A版(2019)高中數學必修第二冊 6.1 《平面向量的概念》教學設計
評論
0/150
提交評論