华为机试复习资料.doc_第1页
华为机试复习资料.doc_第2页
华为机试复习资料.doc_第3页
华为机试复习资料.doc_第4页
华为机试复习资料.doc_第5页
已阅读5页,还剩19页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

10.将字符串中的所有字母都替换成该字母的下一个字母#include using namespace std;#include #include #include void func(char *p);void main() char str120; printf(enter:); gets(str1); func(str1); puts(str1); void func(char *p) char ch; while(*p) ch=*p; if( (*p!=z)&(*p!=Z) *p=ch+1; else if(*p=z) *p=a; else if(*p=Z) *p=A; p+; 11回文判断#includeusing namespace std;bool func(int m);void main() int m; coutenter a number:m; coutfunc(m)endl;bool func(int m) int i,n=0; i=m; while(i) n=n*10+i%10; i/=10; if(m=n) return true; return false;file:/C|/Users/john/Desktop/华为机试/华为机试/t11回文字符.txt2012-03-07 19:41:08#includeusing namespace std;#includebool is_huiwen(char a,int length) const char *src=a; const char *end; end=src+length-1; while(srcend) if(*src=*end) src+;end-; else return false; return true; int main() int len; char c10; coutenter:c; len=strlen(c); bool h; h=is_huiwen(c,len); if(h) couthui_wenendl; else coutnon_hui_wenendl; return 0;file:/C|/Users/john/Desktop/华为机试/华为机试/T12将一个“1234”的字符串转化为1234整型.txt2012-03-07 19:41:0812.将一个“1234”的字符串转化为1234整型#include #include #include using namespace std;int func(char a);void main() char a=1,2,3,4,0; coutfunc(a)endl; int func(char a) int i=0; int sum=0; while(ai!=0) sum=sum*10+(ai-0); i+; return sum;file:/C|/Users/john/Desktop/华为机试/华为机试/T13求一个二维数组每列的最小值.txt2012-03-07 19:41:0913.求一个二维数组每列的最小值#include using namespace std;void fun(int input34, const int m, const int n, int output4);int main() int input34 = 21,48,86,92, 10,23,12,69, 46,78,49,13; int output4; fun(input, 3, 4, output); cout原二维数组是:endl; for(int i=0; i3; i+) for(int j=0; j4; j+) coutinputij ; coutendl; cout每列最小值是:endl; for (int k=0; k4; k+)file:/C|/Users/john/Desktop/华为机试/华为机试/T13求一个二维数组每列的最小值.txt2012-03-07 19:41:09 coutoutputk ; coutendl; return 0;void fun(int input34, const int m, const int n, int output4) int i = 0; int j = 0; for (i=0; in; i+) outputi = input0i; for (j=0; j inputji) outputi = inputji; file:/C|/Users/john/Desktop/华为机试/华为机试/T14连续字符统计.txt2012-03-07 19:41:0914.连续字符统计(如AABCCCD:A2B1C3D1)#include #include #include using namespace std;void func(char str,int len);void main() char str20; int len; coutenter:; gets(str); len=strlen(str); func(str,len);void func(char str, int len) int count=1; int i; for(i=0;ilen;i+) if(stri=stri+1) count+; else coutstricount; count=1;file:/C|/Users/john/Desktop/华为机试/华为机试/T14连续字符统计.txt2012-03-07 19:41:09 coutendl;file:/C|/Users/john/Desktop/华为机试/华为机试/T15找出一个字符串中是否包含相同的子字符串.txt2012-03-07 19:41:0915.找出一个字符串中是否包含相同的子字符串(要求子串长度大于等于2)#include #include using namespace std;int fun(char* str, int n) char *temp = new charn+2; char *str2 = str; int sum = 0; int outsum = 0; char* t; for(int i = 0; i n; i+) for(int j = 2; j outsum) outsum = sum; if(outsum = 1) return 0; return outsum; int main() char strstr1000; memset(strstr,0,sizeof(strstr); char *s = strstr; cin s; int n =strlen(s); int outsum; outsum = fun(s,n); cout outsum endl; system(pause); return 0; file:/C|/Users/john/Desktop/华为机试/华为机试/T16对一段只含有这几种字符的字符串进行转换.txt2012-03-07 19:41:1016已知:yi er san si wu liu qi ba jiu 分别对应123456789,对一段只含有这几种字符的字符串进行转换,转换成相应的数字 如:yiersansan:1233#include #include using namespace std;char* sss9 = yi, er, san, si, wu, liu, qi, ba, jiu;int fun(char* str) int i; int sum = 0; int d = 0; i = 0; int j; while(stri != 0) if(stri = y | stri = e| stri = w | stri = q | stri = b) d = 2; else if(stri = l | stri = j) d = 3; else if(stri = s) if(stri+1 = a)file:/C|/Users/john/Desktop/华为机试/华为机试/T16对一段只含有这几种字符的字符串进行转换.txt2012-03-07 19:41:10 d = 3; else d = 2; for(int k = 0; k s; int outsum; outsum = fun(s); cout outsum endl; system(pause); return 0;file:/C|/Users/john/Desktop/华为机试/华为机试/T16对一段只含有这几种字符的字符串进行转换.txt2012-03-07 19:41:10 file:/C|/Users/john/Desktop/华为机试/华为机试/T17删除字符串中字符个数最少的字符.txt2012-03-07 19:41:10#include #include using namespace std;char* fun(char* str, int n) int hash256 = 0; char *result = new charn+1; memset(result,0,(n+1)*sizeof(char); for(int i = 0; i n; i+) hashstri+; int min = 0x7fffffff; for(int i = 0; i 256; i+) if(hashi min & hashi != 0) min = hashi; for(int i = 0,j = 0; i s; char *re = NULL; re = fun(s,strlen(s); cout re endl; system(pause); return 0; file:/C|/Users/john/Desktop/华为机试/华为机试/T1找出一个数组中满足2N的元素.txt2012-03-07 19:41:111.找出一个数组中满足2N的元素#include using namespace std;int find(int a,int len);void main() int a=1,2,3,5,7,8,16; int len=sizeof(a)/sizeof(int); coutfind(a,len)endl; int find(int a,int len) int i; int count=0; for(i=0;ilen;i+) if(0=(ai&(ai-1) count+; return count; file:/C|/Users/john/Desktop/华为机试/华为机试/T2(2).txt2012-03-07 19:41:11#include using namespace std;void func(int n, int m, int s, int a);void main() int a9=0; func(9,3,1,a); for(int i=8;i=0;i-) coutai ; coutendl;void func(int n, int m, int s, int a) int s1; int w; s1=s; for(int k=0;k=2;i-) s1=(s1+m-1)%i; if(s1=0) s1=i; w=as1-1; for(int j=s1;ji;j+) aj-1=aj; ai-1=w; file:/C|/Users/john/Desktop/华为机试/华为机试/T2报数.txt2012-03-07 19:41:112.报数:共n个人 从1编号,设从第s个人报号,报到m出队#includeusing namespace std;void Joseph(int n, int m, int s);int main() Joseph(9,3,1); return 0;void Joseph(int n, int m, int s) int i,j,w; int s1 = s; int a100 = 0; for(i = 0; i = 2; i-) s1 = (s1+m-1)%i; /s1每次出圈人的位置file:/C|/Users/john/Desktop/华为机试/华为机试/T2报数.txt2012-03-07 19:41:11 if(s1 = 0) /如果s1等于0,则说明要开始报数的人是最后一个人 s1 = i; /把此时变量i的值赋给s1 w = as1-1; /把每次出圈人的序号赋给w for(j = s1; j = 0; k-) coutak ; coutendl;file:/C|/Users/john/Desktop/华为机试/华为机试/T3统计一个数二进制表达中0的个数.txt2012-03-07 19:41:123.统计一个数二进制表达中0的个数(首位1之前0不计)#include using namespace std;int fun(int num);int main() int num; coutnum; coutfun(num) 1; i+; return (i-count);file:/C|/Users/john/Desktop/华为机试/华为机试/T4镜像反转二进制表达式.txt2012-03-07 19:41:124.镜像反转二进制表达式,并输出十进制值#includeusing namespace std;int func(int a);main() int n; coutn; coutfunc(n)1); for(i=0;in;i+) val=val*2+bi; return val;file:/C|/Users/john/Desktop/华为机试/华为机试/T4镜像反转二进制表达式.txt2012-03-07 19:41:12file:/C|/Users/john/Desktop/华为机试/华为机试/T5判断一个字符串中()是否配对.txt2012-03-07 19:41:125.判断一个字符串中()是否配对#includeusing namespace std;bool match(char a,int length);int main() char b100; int len; bool m; coutenter:endl; gets(b); len=strlen(b); m=match(b,len); if(m) coutmatchendl; else coutnonmatchcount1)file:/C|/Users/john/Desktop/华为机试/华为机试/T5判断一个字符串中()是否配对.txt2012-03-07 19:41:12 return false; p+; if(count1=count2) return true; else return false; file:/C|/Users/john/Desktop/华为机试/华为机试/T7查找子字符串个数.txt2012-03-07 19:41:137.查找子字符串个数#include #include using namespace std;int fun(char *str, char *substr);int main() char str100; char substr10; cout输入字符串:n; gets(str); cout输入字串:n; gets(substr); coutfun(str, substr)endl; return 0;int fun(char *str, char *substr) int count = 0; while (*str) char *p = str; char *q = substr; file:/C|/Users/john/Desktop/华为机试/华为机试/T7查找子字符串个数.txt2012-03-07 19:41:13 while (*q) if (*p = *q) p+; q+; else break; if (*q = 0) str = str + strlen(substr); count+; else str+; return count;file:/C|/Users/john/Desktop/华为机试/华为机试/T8数组的循环移位.txt2012-03-07 19:41:138.关于数组的循环移位#include using namespace std;void func(int *p, int n, int k);void main() int a=1,2,3,4,5; int i; func(a,5,2); for(i=0;i5;i+) coutai ; cout=0) while(k) temp=pn-1; for(i=n-1;i0;i-) pi=pi-1; p0=temp; k-; file:/C|/Users/john/Desktop/华为机试/华为机试/T8数组的循环移位.txt2012-03-07 19:41:13 else if(k0) k=k*(-1); while(k) temp=p0; for(i=1;in;i+) pi-1=pi; pn-1=temp; k-; file:/C|/Users/john/Desktop/华为机试/华为机试/链表.txt2012-03-07 19:41:13#include #include #include #include using namespace std;typedef struct student int data; struct student *next;node;/* 链表的创建*/node *creat() node *head,*p,*s; int x; int cycle=1; head=(node*)malloc(sizeof(node); p=head; while(cycle) coutplease enter a numberx; if(x!=0) s=(node*)malloc(sizeof(node); s-data=x; p-next=s;file:/C|/Users/john/Desktop/华为机试/华为机试/链表.txt2012-03-07 19:41:13 p=s; /前一个节点的地址 else cycle=0; head=head-next; p-next=NULL; return (head); void reverse(node *head) node *p1,*p2,*p3; /if(*head=NULL|*head-next=NULL) return *head; p1=*head; p2=p1-next; while(p2) p3=p2-next; p2-next=p1; p1=p2; p2=p3; (*head)-next=NULL; *head=p1; /return *head; file:/C|/Users/john/Desktop/华为机试/华为机试/链表.txt2012-03-07 19:41:13void main() node *p; node *head; /int n; head=(node*)malloc(sizeof(node); head=creat(); /n=length(head); p=head; cout原始链表是:; if(head!=NULL) /原始链表的打印 while(p!=NULL) coutdatanext; coutendl; node *q = &head; reverse(q); p=head; / cout链表长度为:n;/*/ cout逆置后链表是:; if(head!=NULL) /逆置后链表的打印 while(p!=NULL)file:/C|/

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论