华为机试Word文档下载推荐.docx

上传人:b****5 文档编号:19707176 上传时间:2023-01-09 格式:DOCX 页数:22 大小:19.34KB
下载 相关 举报
华为机试Word文档下载推荐.docx_第1页
第1页 / 共22页
华为机试Word文档下载推荐.docx_第2页
第2页 / 共22页
华为机试Word文档下载推荐.docx_第3页
第3页 / 共22页
华为机试Word文档下载推荐.docx_第4页
第4页 / 共22页
华为机试Word文档下载推荐.docx_第5页
第5页 / 共22页
点击查看更多>>
下载资源
资源描述

华为机试Word文档下载推荐.docx

《华为机试Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《华为机试Word文档下载推荐.docx(22页珍藏版)》请在冰豆网上搜索。

华为机试Word文档下载推荐.docx

<

Reverse(str);

2、数字颠倒。

如输入为100,则输出为001

#include<

string>

voidmain()

intnum;

charstr[32];

inti;

cin>

>

num;

itoa(num,str,10);

for(i=strlen(str)-1;

i>

=0;

i--)

cout<

str[i];

3、输入一个int型整数,按照从右向左的阅读顺序,返回一个不含重复数字的新的整数。

voidgetNoRepeatNumber(intnum)

charbuffer[20];

charc[20];

inti,j=0,k,lenbuffer,flag;

memset(buffer,0,20);

itoa(num,buffer,10);

lenbuffer=strlen(buffer);

c[0]=buffer[lenbuffer-1];

for(i=lenbuffer-2;

flag=1;

for(k=0;

k<

j+1;

k++)

if(buffer[i]==c[k])

flag=0;

if(flag)

j=j+1;

c[j]=buffer[i];

j++;

c[j]='

;

for(k=0;

c[k]!

='

c[k];

endl;

getNoRepeatNumber(num);

return0;

4、接受一个十六进制的数值字符串,输出该数值的十进制字符串。

例如输入0XA,输出10。

chara[10];

gets(a);

intlen=strlen(a);

intsum=0,quan=1;

for(inti=len-1;

1;

if(a[i]>

0'

a[i]<

9'

sum=sum+(a[i]-48)*quan;

quan=quan*16;

elseif(a[i]>

A'

F'

sum+=(a[i]-55)*quan;

quan*=16;

elseif(a[i]>

a'

f'

sum+=(a[i]-87)*quan;

sum<

5、输入一个正整数,按照从小到大的顺序输出它的所有质数的因子(如180的质数因子为22335)

voidgetResult(longintinput)

for(inti=2;

i<

=input;

i++)

while((0==input%i)&

input!

=0)

cout<

"

"

input=input/i;

intmain()

inta;

a;

getResult(a);

6、输入A和B的最小公倍数。

输入57,输出35。

intgdc(intx,inty)

return(!

y)?

x:

gdc(y,x%y);

inta,b;

b;

(a*b)/gdc(a,b)<

7、匹配字符串。

boolCompareString(char*shortstr,char*longstr)

intshortLength;

intlongLength;

shortLength=strlen(shortstr);

longLength=strlen(longstr);

if(longLength<

=0||shortLength<

=0)

returnfalse;

for(inti=0;

i<

shortLength;

i++)

for(intj=0;

j<

longLength;

j++)

if((*(shortstr+i))==(*(longstr+j)))

break;

if(j>

=longLength)

returntrue;

char*shortstr=newchar[100];

char*longstr=newchar[100];

boolresult;

shortstr;

longstr;

result=CompareString(shortstr,longstr);

result<

8、输出重复的英文字符

在字符串中,将重复(重复次数可以两次以上)的英文字符(字符包括a~z、A~Z)挑选出来输出,不重复的不输出。

输入:

AACCDDAA

输出:

ACD

C语言:

stdio.h>

stdlib.h>

string.h>

#defineMAX_IN_SIZE1000

intprint_repeat_chars(char*pszString)

charcExistChar[52];

intnExistCharCount=0;

intnApperTimes[52];

inti,nStrLen=0;

chartemp;

memset(nApperTimes,0,sizeof(nApperTimes));

nStrLen=strlen(pszString);

for(i=0;

i<

nStrLen;

temp=*(pszString+i);

if(temp>

temp<

Z'

if(nApperTimes[temp-'

]==0)

{

cExistChar[nExistCharCount++]=temp;

}

nApperTimes[temp-'

]++;

elseif(temp>

z'

+26]==0)

+26]++;

nExistCharCount;

temp=cExistChar[i];

]>

1)

printf("

%c"

temp);

+26]>

intmain(void)

charszInString[MAX_IN_SIZE];

scanf("

%s"

szInString);

print_repeat_chars(szInString);

9、笨笨熊搬家打包篇

森林里的笨笨熊今天可开心啦——他买了新房子,乔迁新喜要搬家了。

因此,笨笨熊请了许多好朋友来帮忙搬家,并准备了很多小纸盒用来装需要搬的物品,不过,这些纸盒的容积都是相同的,并且最多只能装两个物品。

但是,为了不打扰太多的朋友,笨笨熊想了个“聪明”办法:

让每个纸盒使用效率最高(注:

只要纸盒容积大于物品的体积之和就认为可以装下;

物品体积不会大于纸盒容积),这样需要的纸盒最少。

为了帮助笨笨熊提前通知朋友,请你根据笨笨熊的办法,帮忙算出:

需要纸盒的最少数目是多少?

输入:

整数V——纸盒的容积;

整数N——物品的总数目N;

输出:

整数M——需要纸盒的最少数目;

C语言

#defineITEMS_COUNT_MAX100

intmy_sort_bubble(int*pSortList,intnListSize)

inti,j;

boolbIfContinue=true;

nListSize-1&

bIfContinue;

i++)

bIfContinue=false;

for(j=nListSize-1;

j>

i;

j--)

if(pSortList[j]>

pSortList[j-1])

bIfContinue=true;

pSortList[j]=pSortList[j]+pSortList[j-1];

pSortList[j-1]=pSortList[j]-pSortList[j-1];

pSortList[j]=pSortList[j]-pSortList[j-1];

intcalc_least_box_count(intnVolume_of_box,intnNum_of_items,int*pnVolume_of_items)

if(nNum_of_items<

=1)

returnnNum_of_items;

my_sort_bubble(pnVolume_of_items,nNum_of_items);

if(pnVolume_of_items[0]>

nVolume_of_box)

return-1;

pnVolume_of_items[i]==nVolume_of_box;

i++);

j=nNum_of_items-1;

for(;

j;

if(pnVolume_of_items[i]+pnVolume_of_items[j]<

=nVolume_of_box)

j--;

if(i==j)

returni+1;

returni;

//i>

j

intnVolume_of_box;

intnNum_of_items;

int*pnVolume_of_items;

%d"

&

nVolume_of_box);

nNum_of_items);

pnVolume_of_items=(int*)malloc(nNum_of_items*sizeof(int));

nNum_of_items;

pnVolume_of_items[i]);

printf("

calc_least_box_count(nVolume_of_box,nNum_of_items,pnVolume_of_items));

10、实现两个合法时间相加。

样例输入:

00:

00:

0000:

01样例输出:

01

intcharToInt(char*ch)

intlen=strlen(ch);

intk=10;

intsum=0;

len;

++i)

sum=sum*k+(ch[i]-'

);

returnsum;

intcountM(char*ch)

intcount=0;

intk=0;

intsum=0;

charb[3][3];

++i){

if(ch[i]<

ch[i]>

){

b[count][k]=ch[i];

k++;

}else{

b[count][k]='

++count;

k=0;

sum=charToInt(b[0])*60*60+charToInt(b[1])*60+charToInt(b[2]);

deleteb;

intmain(){

char*ch1="

23:

12:

56"

char*ch2="

//countM(ch);

intnumber1=countM(ch1);

intnumber2=countM(ch2);

intsum=number1+number2;

inth=0,m=0,s=0;

s=sum%60;

m=(sum/60)%60;

h=(sum/60/60)%24%60;

charch[255];

if(h<

10){

0"

h;

:

if(m<

m;

if(s<

s;

11、逆序链表输出。

样例输入:

1,2,3,4,5样例输出:

5,4,3,2,1

typedefstructtagListNode

intvalue;

structtagListNode*next;

}ListNode;

voidnew_node_create(ListNode**ppstNode,intnValue)

*ppstNode=(ListNode*)malloc(sizeof(ListNode));

(*ppstNode)->

value=nValue;

next=NULL;

voidnew_node_append(ListNode**ppstTail,char*pValue)

ListNode*pstNow;

new_node_create(&

pstNow,atoi(pValue));

(*ppstTail)->

next=pstNow;

*ppstTail=pstNow;

voidlist_create(ListNode**ppstHead)

ListNode*pstTail;

charszInput[100];

char*p;

szInput);

pstTail=*ppstHead;

p=szInput;

szInput[i]!

if(szInput[i]=='

'

szInput[i]='

new_node_append(&

pstTail,p);

p=szInput+i+1;

voidlist_reverse(ListNode**ppstHead)

ListNode*pstNow,*pstPrev,*pstNext;

pstNow=(*ppstHead)->

next;

pstPrev=*ppstHead;

while(pstNow!

=NULL)

pstNext=pstNow->

if(pstPrev==*ppstHead)

pstNow->

else

next=pstPrev;

pstPrev=pstNow;

pstNow=pstNext;

(*ppstHead)->

voidlist_print(ListNode**ppstHead)

pstNow=(*ppstHead)->

while(pstNow->

next!

%d,"

pstNow->

value);

pstNow=pstNow->

voidlist_free(ListNode**ppstHead)

ListNode*pstNow,*pstNext;

free(pstNow);

ListNode*pstHead;

pstHead,0);

list_create(&

pstHead);

list_reverse(&

list_print(&

list_free(&

12、心有灵犀一点通。

3

362452

样例输出:

2

#defineLATTICE_MAX_NUM1000

intscore_calc_man(int*pLatticeList,intnPos)

inti,nScore=0;

=nPos;

nScore=nScore+=pLatticeList[i];

returnnScore;

intscore_calc_lady(int*pLatticeList,intnPos,intnListSzie)

for(i=nPos;

nListSzie;

intprivity_calc(int*pLatticeList,intnListSzie)

intnManScoreList[LATTICE_MAX_NUM];

intnLadyScoreList[LATTICE_MAX_NUM];

inti,j,nCount=0;

nManScoreList[i]=score_calc_man(pLatticeList,i);

nLadyScoreList[i]=score_calc_lady(pLatticeList,i,nListSzie);

for(j=0;

j<

if(nLadyScoreList[j]==nManScoreList[i])

nCount++;

returnnCount;

intnCoupleCount;

in

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 自然科学 > 物理

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1