亚信校招笔试题目.docx
- 文档编号:8413147
- 上传时间:2023-01-31
- 格式:DOCX
- 页数:17
- 大小:27.49KB
亚信校招笔试题目.docx
《亚信校招笔试题目.docx》由会员分享,可在线阅读,更多相关《亚信校招笔试题目.docx(17页珍藏版)》请在冰豆网上搜索。
亚信校招笔试题目
publicclassBSTMinLength{
publicstaticvoidmain(String[]args){
TreeNodetNode11=newTreeNode(10,null,null);
TreeNodetNode12=newTreeNode(50,null,null);
TreeNodetNode13=newTreeNode(5,null,null);
TreeNodetNode14=newTreeNode(30,null,null);
TreeNodetNode21=newTreeNode(30,tNode11,tNode12);
TreeNodetNode22=newTreeNode(30,tNode13,tNode14);
TreeNodetNodeRoot=newTreeNode(100,tNode21,tNode22);
}
privatestaticintminlength(TreeNodetNode)
{
if(tNode!
=null){
returngetlength(tNode,0);
}
return-1;
}
privatestaticintgetlength(TreeNodetNode,intcurLength){
intminLeft=-1;
intminRight=-1;
if!
=null){
minLeft=getlength,curLength+;
}
if!
=null){
minRight=getlength,curLength+;
}
if==null&&==null){
returncurLength+;
}
if==null){
returnminRight;
}
if==null){
returnminLeft;
}
returnminLeft>minRightminRight:
minLeft;
}
}
classTreeNode{
intvalue;
TreeNodeleftNode;
TreeNoderightNode;
TreeNode(intvalue,TreeNodelefeNode,TreeNoderightNode){
=value;
=lefeNode;
=rightNode;
}
}
#include
usingnamespacestd;
intlruCountMiss(intmax_cache_size,int*pages,intlen)
{
intcount=0;
inti,j,k,n;
boolflag=false;
int*a=newint[max_cache_size];
转链表
lnode*reverse(lnode*head){
if(head){
lnode*prev=NULL;
lnode*curr=head;
lnode*next=curr->next;
curr->next=prev;
while(next!
=NULL){
prev=curr;
curr=next;
next=next->next;
curr->next=prev;
}
returncurr;
}else{
returnhead;
}
};
lnode*reverseLinkedList(lnode*list){
if(list){
lnode*ori=list;
lnode*half=list;
lnode*prev=list;
while(list&&half&&half->next){
prev=list;
list=list->next;
half=half->next;
if(half){
half=half->next;
}
}
if(list){
prev->next=reverse(list);
}
returnori;
}
returnlist;
}
4.SJF
floatwaitingTimeSJF(int*requestTimes,int*durations,intn){
int*flags=newint[n];
floatsums=0;
for(inti=0;i flags[i]=-1; } intnowtime=0; for(inti=0;i intcount=0; for(intk=0;k if(count==0){ if(requestTimes[k]<=nowtime&&durations[k]>=0){ flags[count++]=k; } } else{ if(durations[k]>=0&&requestTimes[k]<=nowtime){ if(durations[k] count=1; flags[0]=k; }elseif(durations[k]==durations[flags[0]]){ flags[count++]=k; } } } } if(count==0){ count=1; for(intj=0;j if(durations[j]>=0){ flags[0]=j; nowtime=requestTimes[j]; } } } intidx=flags[0]; intminreq=requestTimes[flags[0]]; intmindrus=durations[idx]; if(count>1){ for(intj=1;j if(requestTimes[flags[j]] minreq=requestTimes[flags[j]]; idx=flags[j]; } } } sums+=nowtime-requestTimes[idx]; nowtime+=durations[idx]; requestTimes[idx]=-1; durations[idx]=-1; } returnsums/n; } 5无向连通判断是否为树 #include<> #include<> #include<> constintN=10000,M=100000; booledge[N][N];老鼠奶酪 #include usingnamespacestd; intisPath(int**grid,intm,intn); struct_TraversedNode{ intx; inty; _TraversedNode*next; }; struct_Node{ intx; inty; }; intmain(intargc,constchar*argv[]) { int**grid=newint*[8]; for(inti=0;i<8;i++) { grid[i]=newint[8]; } grid[0][0]=1;grid[0][1]=1;grid[0][2]=0;grid[0][3]=0;grid[0][4]=0;grid[0][5]=0;grid [0][6]=0;grid[0][7]=1; grid[1][0]=1;grid[1][1]=1;grid[1][2]=1;grid[1][3]=1;grid[1][4]=1;grid[1][5]=1;grid [1][6]=1;grid[1][7]=1; grid[2][0]=1;grid[2][1]=0;grid[2][2]=0;grid[2][3]=0;grid[2][4]=1;grid[2][5]=0;grid [2][6]=0;grid[2][7]=1; grid[3][0]=1;grid[3][1]=1;grid[3][2]=1;grid[3][3]=0;grid[3][4]=1;grid[3][5]=0;grid [3][6]=0;grid[3][7]=1; grid[4][0]=0;grid[4][1]=1;grid[4][2]=0;grid[4][3]=0;grid[4][4]=1;grid[4][5]=1;grid [4][6]=1;grid[4][7]=1; grid[5][0]=0;grid[5][1]=1;grid[5][2]=0;grid[5][3]=0;grid[5][4]=0;grid[5][5]=0;grid [5][6]=0;grid[5][7]=1; grid[6][0]=0;grid[6][1]=1;grid[6][2]=0;grid[6][3]=9;grid[6][4]=1;grid[6][5]=1;grid [6][6]=1;grid[6][7]=1; grid[7][0]=0;grid[7][1]=1;grid[7][2]=1;grid[7][3]=1;grid[7][4]=0;grid[7][5]=0;grid [7][6]=1;grid[7][7]=0; for(inti=0;i<8;i++) { for(intj=0;j<8;j++) cout< cout< returnisPath(grid,8,8); } intisPath(int**grid,intm,intn) { if(grid[0][0]==0)return0; if(grid[0][0]==9)return1; intstep=0; boolflag_down_success=true; boolflag_up_success=true; boolflag_left_success=true; boolflag_right_success=true; _TraversedNode*p=NULL; _TraversedNode*p_check=NULL; _TraversedNode*head=NULL; _TraversedNode*TraversedNode=new_TraversedNode; TraversedNode->x=0; TraversedNode->y=0; head=TraversedNode; p=TraversedNode; p->next=NULL; intcount_node=0; intnum_node=1; _Node*node=new_Node[n+m]; _Node*node_next=new_Node[n+m]; node[0].x=0; node[0].y=0; while (1) { for(inti=0;i { if(node[i].x+1<=m-1) { if(grid[node[i].x+1][node[i].y]! =0) { if(grid[node[i].x+1][node[i].y]==9) { step++; cout<<"可以最短"< return1; } p_check=head; while(p_check! =NULL) { if((p_check->x==node[i].x+1)&&(p_check->y==node[i].y)) { p_check=NULL; flag_down_success=false; } else { p_check=p_check->next; } } if(flag_down_success) { TraversedNode=new_TraversedNode; TraversedNode->x=node[i].x+1; TraversedNode->y=node[i].y; p->next=TraversedNode; p=TraversedNode; p->next=NULL; node_next[count_node].x=node[i].x+1; node_next[count_node].y=node[i].y; count_node++; } flag_down_success=true; } } if(node[i].x-1>=0) { if(grid[node[i].x-1][node[i].y]! =0) { if(grid[node[i].x-1][node[i].y]==9) { step++; cout<<"可以最短"< return1; } p_check=head; while(p_check! =NULL) { if((p_check->x==node[i].x-1)&&(p_check->y==node[i].y)) { p_check=NULL; flag_up_success=false; } else { p_check=p_check->next; } } if(flag_up_success) { TraversedNode=new_TraversedNode; TraversedNode->x=node[i].x-1; TraversedNode->y=node[i].y; p->next=TraversedNode; p=TraversedNode; p->next=NULL; node_next[count_node].x=node[i].x-1; node_next[count_node].y=node[i].y; count_node++; } flag_up_success=true; } } if(node[i].y+1<=n-1) { if(grid[node[i].x][node[i].y+1]! =0) { if(grid[node[i].x][node[i].y+1]==9) { step++; cout<<"可以最短"< return1; } p_check=head; while(p_check! =NULL) { if((p_check->x==node[i].x)&&(p_check->y==node[i].y+1)) { p_check=NULL; flag_right_success=false; } else { p_check=p_check->next; } } if(flag_right_success) { TraversedNode=new_TraversedNode; TraversedNode->x=node[i].x; TraversedNode->y=node[i].y+1; p->next=TraversedNode; p=TraversedNode; p->next=NULL; node_next[count_node].x=node[i].x; node_next[count_node].y=node[i].y+1; count_node++; } flag_right_success=true; } } if(node[i].y-1>=0) { if(grid[node[i].x][node[i].y-1]! =0) { if(grid[node[i].x][node[i].y-1]==9) { step++; cout<<"可以最短"< return1; } p_check=head; while(p_check! =NULL) { if((p_check->x==node[i].x)&&(p_check->y==node[i].y-1)) { p_check=NULL; flag_left_success=false; } else { p_check=p_check->next; } } if(flag_left_success) { TraversedNode=new_TraversedNode; TraversedNode->x=node[i].x; TraversedNode->y=node[i].y-1; p->next=TraversedNode; p=TraversedNode; p->next=NULL; node_next[count_node].x=node[i].x; node_next[count_node].y=node[i].y-1; count_node++; } flag_left_success=true; } } } if(count_node==0) { cout<<"不存在到达终点的路径"< return0; break; } step++; num_node=count_node; count_node=0; for(inti=0;i { node[i].x=node_next[i].x; node[i].y=node_next[i].y; cout<<"("< } cout< } } 7.格雷码 publicstaticintgray(byteterm1,byteterm2){ intn=0; for(inti=0;i<8;i++){ bytet1,t2,ch; ch=(byte)0x01; t1=term1&ch; t2=term2&ch; if((t1^t2)==ch){ n++; } term1=(byte)(term1>>1); term2=(byte)(term>>1); } if(n==1) return1; else return0; } 8. #include usingnamespacestd; voidmyPrint(intn) { if(1==n) { cout<<"1*2"< return; } intlastnumber=n*(n+1);序循环链表插入整数 #include<> #include<> #defineN5 typedefstructnode{ intdata; structnode*next; }SN; SN*creatlink(inta[]) { 符串格式化,去掉首尾的空格,以及字符串中间连续的空格,但中间的只保留最后一个空格。 比如: "ilovemeituan",格式化后: "ilovemeituan". 我说一下我的思路: 1.用string的substring方法很轻松去掉首尾的空格。 2,将去掉首尾空格的字符串转化为一个字符数组,方便对空格的查找。 3,将找到的空格的下标记录在一个arrayList(长度可变的优点等)中去。 4,将第1步骤得到的字符串进行切割,最后一个空格前的字符串作为前缀字符串 将(包括最后一个空格的下标)从最后一个下标开始到字符串结尾作为后缀字符串。 5.将前缀字符串中的所有的空格使用replaceAll方法替换为没有“”。 6.将5步骤得到的字符串与后缀字符串进行拼接。 那么就得到了想要的字符串。 代码实现如下; [java] 1.packagetest; 2. 3.import 4. 5.publicclassSolution{ 6.publicstaticStringformatString(StringsourceString){ 7. 8.Strings1=(1,()-1); 9."去掉收尾空格后: "+s1); 10.charch[]=(); 11."转化为字符数组后: "); 12."["); 13.for(charc: ch){ 14.","); 15.} 16."]"); 17. 18.intcount=0; 19.ArrayList 20."字符串中间的空格的下标依次为: "); 21.for(inti=0;i<;i++){ 22.if(ch[i]==32){ 23.count++; 24.(i); 25.","); 26.} 27.} 28. 29.StringprefixString=""; 30.StringsuffixString=""; 31.StringoutString=""; 32."alist的大小: "+()); 33."最后一个下标位置: "+()-1)); 34.StringlaterString=(0,()-1)); 35.prefixString=("",""); 36.suffixString=()-1),()); 37.outString=prefixString+suffixString; 38.returnoutString; 39.} 40.publicstaticvoidmain(Stringargs[]){ 41."ilovemeituan")); 42.} 43.} 结果:
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 亚信校招 笔试 题目