華為校園招聘機試整理及本人華為面試經(jīng)歷_第1頁
華為校園招聘機試整理及本人華為面試經(jīng)歷_第2頁
華為校園招聘機試整理及本人華為面試經(jīng)歷_第3頁
華為校園招聘機試整理及本人華為面試經(jīng)歷_第4頁
華為校園招聘機試整理及本人華為面試經(jīng)歷_第5頁
已閱讀5頁,還剩31頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

更好的修正。希望對后來者有所幫助。1.第一題的題目大概是輸入整型數(shù)組求數(shù)組的最小數(shù)和最大數(shù)之和,例如輸入1,2,3,4則輸出為5,當輸入只有一個數(shù)的時候,則最小數(shù)和最大數(shù)都是該數(shù),例如只輸入1,則輸出為2;另外數(shù)組的長度不超過#include<stdio.h>main()min_num=num[0];{max_num=num[0];num[50]={0};j=0;j<n;j++)i,n;{if(max_num<num[j])printf("請輸入整型數(shù)組的長度(1~50):");max_num=num[j];scanf("%d",&n);elseif(min_num>num[j])min_num=num[j];printf("請輸入整型數(shù)組的元素:");}(i=0;i<n;i++)sum=min_num+max_num;{printf("數(shù)組中最大與最小值之和:%d\n",sum);scanf("%d",&num[i]);}}212333333333333333111111111111111111111111.輸出#include<stdio.h>{#include<string.h>‐‐]=((num1[len_num1‐1]‐'0')+(num2[len#include<malloc.h>_num2‐1]‐'0'));main()}{if(len_num1>0)char*num1,*num2;//兩個長長整型數(shù)據(jù){char*sum;‐‐]=num1[len_num1‐1]'0';//len_num1‐‐;len_num1,len_num2;兩個長長整型數(shù)據(jù)的長度}len_max,len_min;if(len_num2>0)num1=(char*)malloc(sizeof(char));{num2=(char*)malloc(sizeof(char));‐‐]=num1[len_num2‐1]‐'0';printf("輸入兩個長長整型數(shù)據(jù):");len_num2‐‐;scanf("%s",num1);}printf("輸入兩個長長整型數(shù)據(jù):");j=len_max1;j>=0;j‐‐)//實現(xiàn)進位操作scanf("%s",num2);{len_num1=strlen(num1);//temp=sum[j]'0';len_num2=strlen(num2);if(sum[j]>=10)len_max=(len_num1>=len_num2)?{len_num1:len_num2;sum[jlen_min=(len_num1<=len_num2)?sum[j]%=10;len_num1:len_num2;}len_max1=len_max;}sum=(char*)malloc(sizeof(char)*len_max);char*outsum=(char*)malloc(sizeof(char)*len_max1);memset(sum,0x00,len_max+1);//切忌初始化j=0;for(;len_num1>0&&len_num2>0;len_num1‐‐,len_nuwhile(sum[j]==0)//跳出頭部0元素m2‐‐)j++;m=0;m<len_max1;j++,m++)printf("輸出兩長長整型數(shù)據(jù)之和:%s\n",outsum);outsum[m]=sum[j]+'0';outsum[m]='\0';}3.通過鍵盤輸入一串小寫字母(a~z)組成的字符串。請編寫一個字符串過濾程序,若字符串中出現(xiàn)多個相同的字符,將非首次出現(xiàn)的字符過濾掉。比如字符串“abacacde”過濾結果為“abcde要求實現(xiàn)函數(shù):stringFilter(constcharlInputLen,char*pOutputStr);【輸入】pInputStr:輸入字符串lInputLen:輸入字符串長度【輸出】pOutputStr:輸出字符串,空間已經(jīng)開辟好,與輸入字符串等長;#include#include<string.h>#include<malloc.h>stringFilter(constcharlonglen,char*p_outstr){char*tmp=j=0;j<len;j++){if(array[tmp[j]]==0)*p_outstr++=tmp[j];}='\0';}main(){char="cccddecc";len=char*=(char*)malloc(len*sizeof(char));printf("%s\n",outstr);=NULL;}4.通過鍵盤輸入一串小寫字母(a~z)組成的字符串。請編寫一個字符串壓縮程序,將字符串中連續(xù)出席的重復字母進行壓縮,并輸出壓縮后的字符串。

壓縮規(guī)則:1.僅壓縮連續(xù)重復出現(xiàn)的字符。比如字符串"abcbc"由于無連續(xù)重復字符,壓縮后的字符串還是

"abcbc".2.壓縮字段的格式為"字符重復的次數(shù)+字符"。例如:字符串"xxxyyyyyyz"壓縮后就成為"3x6yz"要求實現(xiàn)函數(shù):voidstringZip(constchar*pInputStr,longlInputLen,char*pOutputStr);【輸入】pInputStr:輸入字符串lInputLen:輸入字符串長度【輸出】pOutputStr:輸出字符串,空間已經(jīng)開辟好,與輸入字符串等長;#include{#include<string.h>*p_outstr++=p_str[i];#include<malloc.h>}=1;//注意其位置stringZip(constcharlonglen,char}{}='\0';i=0;i<len;i++)}{if(p_str[i]==p_str[i+1])main(){{count++;char="cccddecc";}printf("壓縮之前的字符串為:%s\n",str);elselen={char*=(char*)malloc(len*sizeof(char));if(count>1){printf("壓縮之后的字符串為:%s\n",outstr);*p_outstr++=+'0';*p_outstr++=p_str[i];=NULL;}}else5.通過鍵盤輸入100以內(nèi)正整數(shù)的加、減運算式,請編寫一個程序輸出運算結果字符串。輸入字符串的格式為:“操作數(shù)1運算符操作數(shù)2”,“操作數(shù)”與“運算符”之間以一個空格隔開。補充說明:1.操作數(shù)為正整數(shù),不需要考慮計算結果溢出的情況。2.若輸入算式格式錯誤,輸出結果為“0”。要求實現(xiàn)函數(shù):voidarithmetic(constchar*pInputStr,longlInputLen,char*pOutputStr);【輸入】pInputStr:輸入字符串

lInputLen:輸入字符串長度【輸出】pOutputStr:輸出字符串,空間已經(jīng)開辟好,與輸入字符串等長;#include#include<string.h>#include<stdlib.h>arithmetic(constchar*input,longchar*output){chars1[10];chars2[10];chars3[10];=len_input=strlen(input);i=0;i<len_input;++i){if(input[i]=='')cnt++;}if(cnt!=2){*output++='0';*output='\0';}sscanf(input,"%s%s%s",s1,s2,s3);if(strlen(s2)!=1||(s2[0]!='+'&&s2[0]!='‐')){*output++='0';*output='\0';}len_s1=strlen(s1);for(i=0;i<len_s1;i++){if(s1[i]<'0'||s1[i]>'9'){*output++='0';*output='\0';}}len_s3=strlen(s3);for(i=0;i<len_s3;i++){if(s3[i]<'0'||s3[i]>'9'){*output++='0';*output='\0';}}x=y=if(s2[0]=='+'){=x+y;itoa(result,output,10);}elseif(s2[0]=='‐'){=itoa(result,output,10);}else{*output++='0';*output='\0';}}main(){char={"10‐23"};charoutstr[10];len=printf("%s\n",str);printf("%s\n",outstr);}6.n(約瑟夫環(huán)是一個數(shù)學的應用問題:已知n123...nk的人開始報數(shù),數(shù)到m的那個人出列;他的下一個人又從1開始報數(shù),數(shù)到m的那個人又出列;依此規(guī)律重復下#include#include<string.h>#include<stdlib.h>#include<malloc.h>Node{Node}LinkList;LinkListn){LinkListi=1;p=(LinkList*)malloc(sizeof(LinkList));p‐for(i=1;i<=n;i++){q=(LinkList*)malloc(sizeof(LinkList));q‐>data=i+1;p‐>next=q;p=q;}p‐//使鏈表尾連接鏈表頭,形成循環(huán)鏈表free(p);p=NULL;free(q);q=NULL;}deletefun(LinkList*L,intm){LinkList*p,*q,*temp;i;p=L;while(p‐>next!=p){for(i=1;i<m;i++){q=p;p=p‐>next;}printf("%5d",p‐temp=p;q‐>next=p‐p=p‐>next;free(temp);}printf("%5d\n",p‐}main(){n=7,m=3;LinkListdeletefun(head1,m);}7..“0‐10”和“如輸入“3,3,4,5,6,7,7”#include<stdio.h>#include<stdlib.h>#include<string.h>main(){charstr[100];printf("輸入一組字符串:\n");scanf("%s",&str);len=strlen(str);i=0;i<len;i++){if(str[i]>='0'&&str[i]<='9')‐'0';}j=0;j<count;j++){elseif(min>array[j])}k=0;k<count;k++){if(array[k]==min)‐‐;‐‐;}printf("%d\n",result);}8.輸入一組身高在到1905身高高的那兩個身高;從小到大輸出;如輸入181186190輸出#include<stdio.h>#include<stdlib.h>N5main(){Height[N];dmin;H1,H2;printf("請輸入一組身高在到190之間的數(shù)據(jù)(共5個):\n");k=0;k<N;k++)scanf("%d",&Height[k]);printf("\n");for(i=0;i<N;i++)for(j=1;j<N‐i&&Height[j‐1]>Height[j];j++){temp=Height[j‐1];Height[j‐1]=Height[j];Height[j]=temp;}H1=Height[0];H2=Height[1];dmin=H2‐H1;m=2;m<N;m++){if(Height[m]Height[m‐1]<=dmin){H1=Height[m1];H2=Height[m];dmin=Height[m]‐Height[m1];}}printf("身高差最小的兩個身高為:\n");printf("%d,%d\n",H1,H2);}9.刪除子串,只要是原串中有相同的子串就刪掉,不管有多少個,返回子串個數(shù)。

#include#include<stdlib.h>#include<assert.h>#include<string.h>char{!=NULL&&!=NULL);char*p,*q;char*t,*temp;p=q=sub_str;t==0;n=strlen(q);=(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);}main(){chars[100]={‘\0’};num=printf(“Thenumbersub_strisprintf(“Theis}10.要求編程實現(xiàn)上述高精度的十進制加法。要求實現(xiàn)函數(shù):voidadd(constchar*num1,constchar*num2,char*result)【輸入】num1:字符串形式操作數(shù)1,如果操作數(shù)為負,則num1[0]為符號位num2:字符串形式操作數(shù)2,如果操作數(shù)為負,則num2[0]為符號位'-'【輸出】result:保存加法計算結果字符串,如果結果為負,則result[0]為符號位。#include<stdio.h>#include<stdlib.h>#include<string.h>move(char//移除字母前的"‐"符號{if(str[0]!='')i;=0;i<‐i++)=str[i+1];='\0';}{=i=‐1;i>0;i‐‐)//從最后開始移除0,直到遇到非0數(shù)字,只對最初位置上的0不予判斷{=='0'){='\0';count++;}else‐}‐}//將字符串倒轉{chari=0;i<=‐i++){==‐1‐i];‐1‐=}}*str1,char*str2,charboolflag){len1=strlen(str1);len2=strlen(str2);n1,n2,another=表示進位=0;//表示的當前位數(shù)i,j;curSum;=len1‐1,j=len2‐1;i>=0&&j>=0;i‐‐,j‐‐){n1=str1[i]‐'0';n2=str2[j]‐'0';curSum=n1+n2+another;=curSum%+'0';another=curSum/10;}if(j<0){while(i>=0)//遍歷剩余各位{n1=‐‐]‐'0';curSum=+another;=curSum%10+'0';another=curSum/10;}if(another!=0)//如果還有進位未加上=another+'0';}else{while(j>=0){n2=str2[j]‐'0';curSum=+another;=curSum%10+'0';another=curSum/10;}if(another!=0)=another+'0';}='\0';=if(!flag){='‐='\0';}}real_minus(char*str1,char*str2,char//減去{charbig[100],small[100];big_len,sml_len;len1=strlen(str1);len2=strlen(str2);boolflag=//用于標記大if(len1<len2)flag=true;elseif(len1==len2){==0){='0';='\0';}elseif(strcmp(str1,str2)<0)flag=true;}if(flag)//將和交換,確保指向的值是其中較大者,最后通過flag確定要不要給前面加‐號{char*temp===len1=len2=}n1,n2,another=表示是否有借位i,j;=0;curMinus;=len1‐j=len21;&&j>=0;i‐‐,j‐‐){n1=str1[i]‐'0';n2=str2[j]‐'0';if(n1>=n2+another){=(n1‐n2another)+'0';another=}else{=(n1+10n2‐another)+'0';another=}}while(i>=0){n1=str1[i‐‐]‐'0';if(another!=0){n1‐=another;another=}=n1+'0';}='\0';=if(flag){='‐='\0';}}char*num1,char*num2,char{len1=strlen(num1);len2=strlen(num2);if(!len1||!len2)charstr1[100],str2[100];num1,len1);str1[len1]='\0';num2,len2);str2[len2]='\0';if(str1[0]==‐'&&str2[0]==‐'){len1);len2);=}elseif(str1[0]==‐'){len1);=real_minus(str2,}elseif(str2[0]=='‐'){len2);=real_minus(str1,}else=true);}//intmain(intcharmain(){charnum1[100],num2[100];printf("請輸入兩個整型數(shù)據(jù):\n");scanf("%s%s",num1,num2);charresult[100];memset(result,100);addi(num1,num2,printf("%s\n",}11.描述:10個學生考完期末考試評卷完成后,A老師需要劃出及格線,要求如下:(1)及格線是10的倍數(shù);(2)保證至少有60%的學生及格;(3)如果所有的學生都高于60分,則及格線為60分輸入:輸入10個整數(shù),取值0~100輸出:輸出及格線,10的倍數(shù)#include<stdio.h>bubblesort(intarr[]){for(i=0;i<10;i++)for(j=0;j<9‐i&&arr[j]>arr[j+1];j++){temp=arr[j];arr[j]=arr[j+1];arr[j+1]=temp;}}a[]){bubblesort(a);if(a[0]>=60)60;else}main(){a[10]={0};printf("請隨機輸入10個成績(0‐100\n");scanf("%d%d%d%d%d%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9]);printf("\n");printf("及格線為:%d\n",result);}12.描述:一條長廊里依次裝有n(1≤n≤65535)盞電燈,從頭到尾編號1、2、3、…n-1、n。每盞電燈由一個拉線開關控制。開始,電燈全部關著。有n12的倍數(shù)的電燈的開關拉一下;接著第三個學生把號碼凡是3n個學生把號碼凡是n的倍數(shù)的電燈的開關拉一下。n個學生按此規(guī)定走完后,長廊里電燈有幾盞亮著。注:電燈數(shù)和學生數(shù)一致。輸入:電燈的數(shù)量輸出:亮著的電燈數(shù)量樣例輸入:3樣例輸出:1#include<stdio.h>Max_Bubl_Num65535GetLightLampNum(intn){BublNum[Max_Bubl_Num]={0};表示燈滅,1表示燈亮unsignedi,j;unsignedfor(i=1;i<=n;i++)for(j=i;j<=n&&j%i==0;j++){BublNum[j‐1]+=1;BublNum[j‐1]=BublNum[j‐1]%2;}k=0;k<n;k++){if(BublNum[k]==1)count++;}}main(){printf("請輸入燈的數(shù)量(1‐65535):\n");scanf("%d",&n);result=GetLightLampNum(n);printf("最后亮燈的數(shù)量為:%d\n",result);}13.描述:已知2條地鐵線路,其中A為環(huán)線,B為東西向線路,線路都是雙向的。經(jīng)過的站點名分別如下,兩條線交叉的換乘點用表示。編寫程序,任意輸入兩個站點名稱,輸出乘坐地鐵最少需要經(jīng)過的車站數(shù)量(含輸入的起點和終點,換乘站點只計算一次)。地鐵線A(環(huán)線)經(jīng)過車站:A1A2A3A4A5A6A7A8A9T1A10A11A12A13T2A14A15A16A17A18地鐵線B(直線)經(jīng)過車站:B1B2B3B4B5T1B6B7B8B9B10T2B11B12B13B14B15輸入:輸入兩個不同的站名輸出:輸出最少經(jīng)過的站數(shù),含輸入的起點和終點,換乘站點只計算一次輸入樣例:A1A3輸出樣例:3#include<stdio.h>#include<string>#include<queue>#include<vector>usingnamespaceMAX3515node{node}edgenode;charname[10];boolflag;*link;charsubway_name1[SUBWAY_A][10]={"A1","A2","A3","A4","A5","A6","A7","A8","A9","T1","A10","A11","A12","A13","T2","A14","A15","A16","A17","A18"};charsubway_name2[SUBWAY_B][10]={"B1","B2","B3","B4","B5","B6","B7","B8","B9","B10","B11","B12","B13","B14","B15"};i;*p;for(i=0;i<MAX;i++){ga[i].link=NULL;strcpy(ga[i].name,subway_name1[i]);else‐20]);}地鐵建鄰接表‐1;i++){p=(edgenode*)malloc(sizeof(edgenode));p‐‐1;p‐>next=NULL;ga[i].link=p;p=(edgenode*)malloc(sizeof(edgenode));p‐p‐>next=NULL;‐>next=p;if(i==9){p=(edgenode*)malloc(sizeof(edgenode));

p‐p‐>next=NULL;‐‐>next=p;

p=(edgenode*)malloc(sizeof(edgenode));

p‐p‐>next=NULL;‐‐‐>next=p;}elseif(i==14){p=(edgenode*)malloc(sizeof(edgenode));p‐p‐>next=NULL;‐‐>next=p;p=(edgenode*)malloc(sizeof(edgenode));p‐p‐>next=NULL;‐‐‐>next=p;}}p=(edgenode*)malloc(sizeof(edgenode));‐‐1;‐>next=NULL;ga[0].link=p;p=(edgenode*)malloc(sizeof(edgenode));‐‐>next=NULL;‐>next=p;p=(edgenode*)malloc(sizeof(edgenode));‐‐2;‐>next=NULL;‐1].link=p;p=(edgenode*)malloc(sizeof(edgenode));‐‐>next=NULL;‐‐>next=p;//B地鐵建鄰接表‐1;i++){if(i==4||i==5||i==9||i==10)p=(edgenode*)malloc(sizeof(edgenode));p‐‐1;p‐>next=NULL;p=(edgenode*)malloc(sizeof(edgenode));p‐p‐>next=NULL;‐>next=p;}p=(edgenode*)malloc(sizeof(edgenode));‐‐>next=NULL;p=(edgenode*)malloc(sizeof(edgenode));‐‐>next=NULL;‐>next=p;p=(edgenode*)malloc(sizeof(edgenode));‐‐>next=NULL;p=(edgenode*)malloc(sizeof(edgenode));‐‐>next=NULL;‐>next=p;p=(edgenode*)malloc(sizeof(edgenode));‐‐>next=NULL;p=(edgenode*)malloc(sizeof(edgenode));‐‐>next=NULL;‐>next=p;p=(edgenode*)malloc(sizeof(edgenode));‐‐>next=NULL;p=(edgenode*)malloc(sizeof(edgenode));‐‐>next=NULL;‐>next=p;p=(edgenode*)malloc(sizeof(edgenode));‐‐>next=NULL;p=(edgenode*)malloc(sizeof(edgenode));‐‐2;‐>next=NULL;‐1].link=p;打印各鄰接節(jié)點for(i=0;i<MAX;i++){printf("%s:",ga[i].name);*s;s=ga[i].link;while(s!=NULL){printf("‐‐s=s‐>next;}printf("\n");}}main(){i;charstr[2][10];while(scanf("%s%s",str[0],str[1])!=EOF){temp=0;for(i=0;i<MAX;i++){if(!strcmp(str[0],ga[i].name))temp=i;}queue<vexnode>q;q.push(ga[temp]);end=1;boolfind_flag=false;while(!q.empty()){if(find_flag)count++;printf("************************\n");printf("第%d層搜索:temp_end=end;while(start<temp_end){find_flag=true;}*s;while(s!=NULL){‐q.push(ga[s‐‐end++;//printf("%s‐}s=s‐>next;}q.pop();}printf("\n");}printf("%d\n",count);}0;}14.字串轉換問題描述:將輸入的字符串(字符串僅包含小寫字母到‘z’a‐>b,b‐‐>z,z‐>a的字符串連續(xù)出現(xiàn)兩個字母相同時,后一個字母需要連續(xù)轉換2次。例如:aabc,zz轉換為ab;當連續(xù)相同字母超過兩個時,第三個出現(xiàn)的字母按第一次出現(xiàn)算。要求實現(xiàn)函數(shù):*input,char*output)【輸入】char*input,輸入的字符串【輸出】char*output,輸出的字符串【返回】無#include<stdio.h>#include<string.h>#include<stdlib.h>*input,char*output){if(input==NULL)chartemp='\0';len_input=strlen(input);i;flag=0;for(i=0;i<len_input;i++){if(input[i]!=temp){output[i]=(input[i]'a'+1)%26+'a';temp=input[i];flag=1;}else{if(flag==1){output[i]=(input[i]'a'+2)%26+'a';temp=input[i];flag=0;}else{output[i]=(input[i]'a'+1)%26+'a';temp=input[i];flag=1;}}}output[i]='\0';}main(){char*input="xyz";charoutput[256];//scanf("%s",input);convert(input,output);printf("%s\n",output);}15.“單詞”的字符串中沒有找到單詞,請輸出空串。輸出的單詞之間使用一個“空格”隔開,最后一個單詞后不加空格。要求實現(xiàn)函數(shù):my_word(charinput[],charoutput[])【輸入】charinput[],輸入的字符串【輸出】charoutput[],輸出的字符串【返回】無#include<string.h>#include<stdlib.h>#includeinput[],charoutput[]){char*p;charcharlen_input=strlen(input);i,j;char=",";char*blank="";i=0;(i=0;i<len_input;i++){if(input[i]<'A'(input[i]>'Z'&&input[i]<'a')||input[i]>'z'){input[i]=',';}}j=0;/*保存取出的單詞*/p=while(NULL!=p){word[j++]=p;p=}for(i=0;i<5;i++)printf("%s",word[i]);/*對單詞按照長度降序排序,冒泡法*/(i=0;i<5;i++){(j=1;j<5‐i;j++){if(strlen(word[j‐1])<strlen(word[j])){‐1];1]=temp;}}}/*刪除相同單詞*/(i=0;i<5;i++){for(j=i+1;j<5;j++){word[j]="\0";}}/*將單詞連接起來輸出*/(j=0;j<5;j++){if(0==j){(output,word[j],strlen(word[j])+1);}else{strcat(output,blank);}};}main(){charinput[]="somelocalsome1234123drivers";printf("篩選之前的字符串:%s\n",input);charoutput[30];my_word(input,output);printf("篩選之后的字符串:%s",output);printf("\n");}16.數(shù)組中數(shù)字都兩兩相同,只有一個不同,找出該數(shù)字:intfindUnique(int*a,intlen){inti=1;inttemp=a[0];for(;i<len;i++)

{temp=temp^a[i];}printf("%d",temp);}17.題目二:數(shù)組中數(shù)字兩兩相同,有兩個不同,找出這兩個:#include<stdlib.h>inta[]={1,1,2,4,3,3,2,5};intfindXorSum(int*a,intlen){inti=0;inttemp=0;for(;i<len;i++){temp=temp^a[i];}returntemp;}intfindFirstBit1(intn){intcount=1;while(!(n&1)){n=n>>1;count++;}returncount;}intisBit1(inta,intcount)

{a=a>>count-1;

return(a&1);}voidfindTwoUnique(int*a,intlen){inti=0;intm=0,n=0;inttemp=findXorSum(a,len);

intcount=findFirstBit1(temp);for(;i<len;i++)

{if(isBit1(a[i],count))

{m=m^a[i];}else{n=n^a[i];}}printf("%d,%d",m,n);}intmain(){findTwoUnique(a,8);}18.一個鏈表和一個數(shù)1→2→3→4→5→6,k=2,則翻轉后2→1→4→3→6→5,若k=3,翻轉后3→2→1→6→5→4,若k=4,翻轉后4→3→2→1→5→6,用程序實現(xiàn)思想:采用遍歷鏈表,分成length/k組,對每組進行逆轉,逆轉的同時要將逆轉后的尾和頭連接起來//#include#include#include"stdlib.h"#include<malloc.h>Node{Node*next;}LinkList;pPre,LinkList*pCur){//鏈表逆轉LinkList*p=NULL;LinkList*=NULL;p=‐LinkList*=NULL;if(pCur!=NULL)pNext=>next;while(p!=pNext){p1=‐>next;p‐==p;p=p1;}}main(){=0,k,i=0,j=0,flag==0;scanf("%d",&k);LinkList*=(LinkList*)malloc(sizeof(LinkList));LinkList*pCur=(LinkList*)malloc(sizeof(LinkList));LinkList*=(LinkList*)malloc(sizeof(LinkList));LinkList*=NULL;LinkList*=NULL;//指向逆轉之后的尾部LinkList*=NULL;‐=1;=pCur;//創(chuàng)建初始鏈表for(i=2;i<=6;i++){LinkList*node=(LinkList*)malloc(sizeof(LinkList));node‐=i;‐=node;pCur=node;}‐=NULL;//最后一定要置NULL,c++中用則無須置NULLpCur=while(pCur!=NULL){length++;pCur=‐}i=0;=length/k;//K段pCur=while(i<=groups){=‐1&&{pCur=‐count++;}{pNext=>next;=pCur;/*沒做翻轉之前的頭部,變成了翻轉之后的尾部*/if(flag==0){‐=}==if(flag==1){=pCur;flag=0;}pCur=pNext;}else{‐=}=pCur;i++;}pCur=while(j<length){j++;‐pCur=‐}printf("\n");//}19.鏈表相鄰元素翻轉,如a‐>b‐>c‐‐>e‐‐g,翻轉后變?yōu)椋篵>a‐>d‐>c‐‐>e‐>g#include#include<stdlib.h>#include<malloc.h>node{charnode*pNext;}Node;Node*n);Node*main(){Node*=}//創(chuàng)建新鏈表Node*n){Node*=(Node*)malloc(sizeof(Node));Node*=‐>pNext=NULL;i;i<n;i++){Node*pNew=(Node*)malloc(sizeof(Node));‐='a'+i;‐>pNext=pNew;‐>pNext=NULL;=pNew;}}Node*p=‐>pNext;isFirst=0;while(p!=NULL){if(isFirst==0){printf("%c",p‐isFirst=1;}else{printf("‐>%c",p‐}p=p‐}}Node*Node*p=‐>pNext;while(p‐>pNext!=NULL&&p‐‐>pNext!=NULL){char=‐p‐‐‐p‐‐p=p‐‐}}20.輸入一串字符串,其中有普通的字符與括號組成(包括(’‘’‘[’,']',要求驗證括號是否匹配,如果匹配則

輸出0、否則輸出1.#include<stdio.h>#include<malloc.h>//#defineMAX100main(){chara[100],c[]="(((1+2))";i=0,j=0;;flag=0;while(c[i]!=NULL&&flag==0){switch(c[i]){case('('):case('['):a[j++]=c[i];break;case(')'):if(a[j‐1]=='('){a[j‐1]='\0';j‐‐;}elseflag=1;case(']'):if(a[j‐1]=='['){a[j‐1]='\0';j‐‐;}elseflag=1;

}i++;}if(j!=0)flag=1;printf("%d\n",flag);}方法2:#include<stdio.h>#include<string.h>#include<stdlib.h>//mchar{}stacknode;*sp;Init(stacknode{‐>top=0;0;}Push(stacknodex){‐>top==m)printf("Theisoverflow!\n");else{‐>top+1;‐>top]=x;}}{‐‐‐1;}main(){chars[m]="(()";i;asp=*)malloc(sizeof(stacknode));Init(sp);printf("Inputa//for(i=0;i<strlen(s);i++){if(s[i]=='(')Push(sp,s[i]);if(s[i]==')')}if(sp‐>top==0)printf("左右括號是匹配的!\n");elseprintf("左右括號是不匹配的!\n");0;}21.將第一行中含有第二行中“23”的數(shù)輸出并排序2.輸入一行數(shù)字:1234235645在輸入第二行:23將第一行中含有第二行中“23”的數(shù)輸出并排序結果即:123423186523#include<stdio.h>sort[t++]=a[j];M}elsemain()temp/=10;{}a[M];‐1;i++)for(j=0;j<t‐i‐1;j++)sort[M],t=0;{charc='';if(sort[j]>sort[j+1])i=0;{while(c!='\n')temp=sort[j+1];{sort[j+1]=sort[j];scanf("%d%c",&temp,&c);sort[j]=temp;a[i++]=temp;}}}scanf("%d",&s);for(i=0;i<t;i++)for(j=0;j<i;j++)printf("%d",sort[i]);{printf("\n");temp=a[j];if(temp%100==s)}{22輸入m個字符串和一個整數(shù)n,把字符串M化成以N為單位的段,不足的位數(shù)用0補齊。如n=8m=9,123456789劃分為:1234567890000000123化為:12300000#include<stdio.h>{#include<string.h>j=i%n;printf("%c",c[i‐1]);main()if(j==0){printf("\n");charc[200]={'\0'};}scanf("%s",&c);if(j!=0)n,i,j;for(i=j+1;i<=n;i++)len=strlen(c);printf("0");scanf("%d",&n);for(i=1;i<=len;i++)}23將電話號碼onenine翻譯成1290中間會有double例如輸入:輸出:123輸入:輸出:1222輸入:輸出:輸入:輸出:有空格,非法字符,兩個Double相連,Double位于最后一個單詞都錯誤#include<stdio.h>if(d==1)#include<stdlib.h>{#include<string.h>printf("%d",j);main()d=0;{}char}a[11][11]={"zero","one","two","three","four","five","six","elseif(!strcmp(temp,a[j])&&j==10)seven","eight","nine","double"};{chartemp[11],c='';d=1;f=1;while(c!='\n')}{}scanf("%s%c",&temp,&c);if(f==0)f=0;for(j=0;j<11;j++)}{if(d==1||f==0)if(!strcmp(temp,a[j])&&j<10)printf("error\n");{printf("\n");printf("%d",j);f=1;}24.將整數(shù)倒序輸出,剔除重復數(shù)據(jù)123365440不帶重復數(shù)字的,所以上面的輸出是456321和571。如果是負數(shù),比如輸入‐175,輸出‐571。#include<stdio.h>for(i=0;i<len1;i++)#include<stdlib.h>{#include<string.h>temp=input[i]‐'0';#include<malloc.h>if(a[temp]==0){main()n[count++]=temp;{a[temp]=1;char*input=(char*)malloc(sizeof(char));}scanf("%s",input);}a[10]={0},i,flag=0,flag1=0;n[count]='\0';len=strlen(input);if(flag==1)if(input[0]=='printf("‐");{flag=1;‐1;ii>=0;ii‐‐)for(i=0;i<len;i++){input[i]=input[i+1];if(n[ii]!=0||flag1!=0)}{len1=strlen(input);printf("%d",n[ii]);flag1=1;}}printf("\n");}25.編程的時候,if條件里面的“”、“)”括號經(jīng)常出現(xiàn)不匹配的情況導致編譯不過,請編寫程序檢測輸入一行ifif((a==1)&&(b==1))是正確的,而if((a==1))&&(b==1))是錯誤的。注意if語句的最外面至少有一對括號。提示:用堆棧來做。輸入:if((a==1)&&(b==1))輸出:RIGTH33輸入:if((a==1))&&(b==1))輸出:WRONG34#include<stdio.h>right++;#include<string.h>‐1]==1&&k>0)main(){{‐1]=0;chars[800]={'\0'};‐‐;scanf("%s",&s);}//chars[]="if(())";elselen=strlen(s);flag=0;i,left=0,right=0;}a[50],k=0,flag=1;if((i==2&&s[i]!='(')||(i==len1&&s[i]!=')'))for(i=0;i<len;i++)flag=0;{}if(s[i]=='(')if(a[0]==0&&flag!=0){printf("RIGHT");left++;elsea[k]=1;printf("WRONG");k++;printf("%d%d\n",left,right);}elseif(s[i]==')')}{約瑟夫問題0計數(shù)到m后,將數(shù)列該位置數(shù)值替換計數(shù)值m,并將數(shù)列該位置數(shù)值出列,然后從下一位置從新開始計數(shù),直到數(shù)列所有數(shù)值出列為止。如果計數(shù)到達數(shù)列尾段,則返回數(shù)列首位置繼續(xù)計數(shù)。請編程實現(xiàn)上述計數(shù)過程,同時輸出數(shù)值出列的順序比如:輸入的隨機數(shù)列為:3,1,2,4,初始計數(shù)值m=7,從數(shù)列首位置開始計數(shù)(數(shù)值所在位置)第一輪計數(shù)出列數(shù)字為,計數(shù)值更新m=2,出列后數(shù)列為3,1,4,從數(shù)值所在位置從新開始計數(shù)第二輪計數(shù)出列數(shù)字為,計數(shù)值更新m=3,出列后數(shù)列為1,4,從數(shù)值1所在位置開始計數(shù)第三輪計數(shù)出列數(shù)字為,計數(shù)值更新m=1,出列后數(shù)列為4,從數(shù)值4所在位置開始計數(shù)最后一輪計數(shù)出列數(shù)字為,計數(shù)過程完成。輸出數(shù)值出列順序為:2,3,1,4。要求實現(xiàn)函數(shù):voidarray_iterate(intlen,intinput_array[],intm,intoutput_array[])【輸入】len:輸入數(shù)列的長度;intintput_array[]:輸入的初始數(shù)列intm:初始計數(shù)值【輸出】output_array[]:輸出的數(shù)值出列順序【返回】無示例:輸入:intinput_array[]={3,1,2,4},intlen=4,m=7輸出:output_array[]={2,3,1,4}解題思路:每次出列一個數(shù)值,需要對m、input_array、output_array、輸出位置outPos、起始位置startPos進行更新;對于輸出位置outPos的計算是關鍵!通過分析可知,outPos=(startPos+m-1)%num代碼實現(xiàn):viewplaincopytoclipboardprint?#include<stdio.h>voidprint_array(intlen,intarray[]){for(inti=0;i<len;i++)printf("%d",array[i]);printf("\n");}//input_array:a[0]...a[len-1]voidarray_iterate(intlen,intinput_array[],intm,intoutput_array[]){int

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論