华为上机程序题Word文件下载.docx

上传人:b****6 文档编号:17946629 上传时间:2022-12-12 格式:DOCX 页数:27 大小:24.95KB
下载 相关 举报
华为上机程序题Word文件下载.docx_第1页
第1页 / 共27页
华为上机程序题Word文件下载.docx_第2页
第2页 / 共27页
华为上机程序题Word文件下载.docx_第3页
第3页 / 共27页
华为上机程序题Word文件下载.docx_第4页
第4页 / 共27页
华为上机程序题Word文件下载.docx_第5页
第5页 / 共27页
点击查看更多>>
下载资源
资源描述

华为上机程序题Word文件下载.docx

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

华为上机程序题Word文件下载.docx

for(intk=0;

k<

k++)

if(array[k]==min)

result–;

if(array[k]==max)

printf(“%d\n”,result);

11.描述:

10个学生考完期末考试评卷完成后,A老师需要划出及格线,要求如下:

(1)及格线是10的倍数;

(2)保证至少有60%的学生及格;

(3)如果所有的学生都高于60分,则及格线为60分

输入:

输入10个整数,取值0~100

输出:

输出及格线,10的倍数

voidbubblesort(intarr[])

inti,j,temp;

for(i=0;

10;

for(j=0;

9-i&

arr[j]>

arr[j+1];

temp=arr[j];

arr[j]=arr[j+1];

arr[j+1]=temp;

intGetPassLine(inta[])

bubblesort(a);

if(a[0]>

=60)

return60;

else

return(((int)a[4]/10)*10);

main()

inta[10]={0};

intresult;

printf(“请随机输入10个成绩(0-100):

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”);

result=GetPassLine(a);

printf(“及格为:

%d\n”,result);

return1;

14.字串转换

问题描述:

将输入的字符串(字符串仅包含小写字母’a'

到’z'

),按照如下规则,循环转换后输出:

a->

b,b->

c,…,y->

z,z->

a;

若输入的字符串连续出现两个字母相同时,后一个字母需要连续转换2次。

例如:

aa转换为bc,zz转换为ab;

当连续相同字母超过两个时,第三个出现的字母按第一次出现算。

要求实现函数:

voidconvert(char*input,char*output)

【输入】char*input,输入的字符串

【输出】char*output,输出的字符串

【返回】无

if(input==NULL)

return;

chartemp=’\0′;

intlen_input=strlen(input);

inti;

intflag=0;

len_input;

if(input[i]!

=temp)

output[i]=(input[i]-’a'

+1)%26+’a'

;

temp=input[i];

flag=1;

if(flag==1)

+2)%26+’a'

flag=0;

}

{output[i]=(input[i]-’a'

output[i]=’\0′;

char*input=”xyz”;

charoutput[256];

// 

scanf(“%s”,input);

convert(input,output);

printf(“%s\n”,output);

15.在给定字符串中找出单词(“单词”由大写字母和小写字母字符构成,其他非字母字符视为单词的间隔,如空格、问号、数字等等;

另外单个字母不算单词);

找到单词后,按照长度进行降序排序,(排序时如果长度相同,则按出现的顺序进行排列),然后输出到一个新的字符串中;

如果某个单词重复出现多次,则只输出一次;

如果整个输入的字符串中没有找到单词,请输出空串。

输出的单词之间使用一个”空格”隔开,最后一个单词后不加空格。

voidmy_word(charinput[],charoutput[])

【输入】charinput[],输入的字符串

【输出】charoutput[],输出的字符串

#include<

voidmy_word(charinput[],charoutput[])

char*p;

char*temp;

char*word[10];

intlen_input=strlen(input);

inti,j;

charexcept[]=“,”;

char*blank=”“;

i=0;

for(i=0;

if(input[i]<

’A’||(input[i]>

’Z'

input[i]<

’a'

)||input[i]>

’z'

input[i]=’,'

j=0;

/*保存取出的单词*/

p=strtok(input,except);

while(NULL!

=p)

word[j++]=p;

p=strtok(NULL,except);

5;

printf(“%s”,word[i]);

/*对单词按照长度降序排序,冒泡法*/

for(j=1;

5-i;

if(strlen(word[j-1])<

strlen(word[j]))

temp=word[j];

word[j]=word[j-1];

word[j-1]=temp;

/*删除相同单词*/

for(j=i+1;

if(strcmp(word[i],word[j])==0)

word[j]=”\0″;

/*将单词连接起来输出*/

for(j=0;

if(0==j)

strncpy(output,word[j],strlen(word[j])+1);

strcat(output,blank);

strcat(output,word[j]);

return;

intmain()

charinput[]=”somelocalbuses,some1234123drivers”;

printf(“筛选之前的字符串:

%s\n”,input);

charoutput[30];

my_word(input,output);

printf(“筛选之后的字符串:

%s”,output);

return0;

22输入m个字符串 

和一个整数n, 

把字符串M化成以N为单位的段,不足的位数用0补齐。

如 

n=8 

m=9 

123456789划分为:

12345678

90000000

123化为 

12300000

charc[200]={‘\0′};

c);

intn,i,j;

intlen=strlen(c);

scanf(“%d”,&

n);

for(i=1;

=len;

j=i%n;

printf(“%c”,c[i-1]);

if(j==0)

if(j!

=0)

for(i=j+1;

=n;

printf(“0″);

28..字符串首字母转换成大写

举例:

thisisabook

返回:

ThisIsABook

charinput[]=”thisisabook”;

charoutput[256]={‘\0′};

inti,len;

len=strlen(input);

printf(“变换前的字符串为:

if(input[0]!

=’‘)

input[0]-=32;

if(input[i]==’‘)

input[i+1]-=32;

output[i]=input[i];

printf(“变换后的字符串为:

%s\n”,output);

29.子串分离 

题目描述:

 

通过键盘输入任意一个字符串序列,字符串可能包含多个子串,子串以空格分隔。

请编写一

个程序,自动分离出各个子串,并使用’,'

将其分隔,并且在最后也补充一个’,'

并将子

串存储。

如果输入”abcdefghi 

d”,结果将是abc,def,gh,i,d, 

voidDivideString(constchar*pInputStr,longlInputLen,char*pOutputStr);

【输入】 

pInputStr:

输入字符串 

lInputLen:

输入字符串长度 

【输出】 

pOutputStr:

输出字符串,空间已经开辟好,与输入字符串等长;

malloc.h>

voidDivideString(constchar*pInputStr,longlInputLen,char*pOutputStr)

intcnt;

constchar*p=pInputStr;

while(*p!

=NULL)

if(*p!

{cnt=0;

*pOutputStr++=*p++;

{cnt++;

p++;

if(cnt==1)

*pOutputStr++=‘,’;

*pOutputStr=‘\0′;

char*str=“abcdefghid”;

longlen=strlen(str);

char*outstr=(char*)malloc(sizeof(str));

//charoutstr[100];

DivideString(str,len,outstr);

printf(“%s”,outstr);

}

华为2014校园招聘的机试题目9月5日亲历

通过键盘输入一串小写字母(a~z)组成的字符串。

请编写一个字符串压缩程序,将字符串中连续出席的重复字母进行压缩,并输出压缩后的字符串。

压缩规则:

1、仅压缩连续重复出现的字符。

比如字符串”abcbc”由于无连续重复字符,压缩后的字符串还是”abcbc”。

2、压缩字段的格式为”字符重复的次数+字符”。

字符串”xxxyyyyyyz”压缩后就成为”3x6yz”。

voidstringZip(constchar*pInputStr,longlInputLen,char*pOutputStr);

输入pInputStr:

输入字符串lInputLen:

输入字符串长度

输出pOutputStr:

输出字符串,空间已经开辟好,与输入字符串等长;

注意:

只需要完成该函数功能算法,中间不需要有任何IO的输入输出

示例

“cccddecc” 

输出:

“3c2de2c”

“adef” 

“adef”

“pppppppp”输出:

“8p”

voidstringZip(constchar*pInputStr,longlInputLen,char*pOutputStr)

inti=lInputLen-1,j=0;

charlast=pInputStr[i],curr;

intcount=1;

for(i=i-1;

i>

=0;

i–)

curr=pInputStr[i];

if(last==curr)

count++;

}else

pOutputStr[j++]=last;

if(count>

1)

pOutputStr[j++]=’0′+count;

count=1;

last=curr;

if(count>

pOutputStr[j++]=’0′+count;

for(i=0;

strlen(pOutputStr)/2;

pOutputStr[i]=pOutputStr[strlen(pOutputStr)-i-1]+pOutputStr[i];

pOutputStr[strlen(pOutputStr)-i-1]=pOutputStr[i]–pOutputStr[strlen(pOutputStr)-i-1];

pOutputStr[i]=pOutputStr[i]–pOutputStr[strlen(pOutputStr)-i-1];

华为2013校园招聘上机笔试题

1字串转换

将输入的字符串(字符串仅包含小写字母‘a’到‘z’),按照如下规则,循环转换后输出:

char*input,输入的字符串

char*output,输出的字符串

【返回】无

char*input="

abcd"

char*output="

bcde"

abbbcd"

bcdcde"

[cpp]viewplaincopyprint?

void 

convert(char 

*input,char 

*output) 

char 

c='

\0'

int 

tag=0;

for(int 

i++) 

=c)//当前字符与前一个字符不相等,则该字符+1 

output[i]=(input[i]-'

a'

+1)%26+'

c=input[i];

tag=1;

}else 

if(tag==1)//当前字符与前一个字符相等,且前面只有一个字符相同 

+2)%26+'

}else//当前字符与前一个字符相等,且前面已有2n个字符相同。

则按第一次出现算 

c=output[i];

voidconvert(char*input,char*output)

charc='

inttag=0;

intlen=strlen(input);

for(inti=0;

{

if(input[i]!

=c)//当前字符与前一个字符不相等,则该字符+1

{

output[i]=(input[i]-'

c=input[i];

tag=1;

}else

if(tag==1)//当前字符与前一个字符相等,且前面只有一个字符相同

{

output[i]=(input[i]-'

c='

tag=0;

}else//当前字符与前一个字符相等,且前面已有2n个字符相同。

则按第一次出现算

c=output[i];

tag=1;

}

}

问题:

输入一个字符串,用指针求出字符串的长度。

答案:

#include

charstr[20],*p;

intlength=0;

printf(“Pleaseinputastring:

”);

gets(str);

p=str;

while(*p++)

length++;

printf(“Thelengthofstringis%d\n”,length);

使用C语言实现字符串中子字符串的替换

描述:

编写一个字符串替换函数,如函数名为StrReplace(char*strSrc,char*strFind,char*strReplace),strSrc为原字符串,strFind是待替换的字符串,strReplace为替换字符串。

举个直观的例子吧,如:

“ABCDEFGHIJKLMNOPQRSTUVWXYZ”这个字符串,把其中的“RST”替换为“ggg”这个字符串,结果就变成了:

ABCDEFGHIJKLMNOPQgggUVWXYZ

答案一:

voidStrReplace(char*strSrc,char*strFind,char*strReplace);

#defineM100;

{chars[]=”ABCDEFGHIJKLMNOPQRSTUVWXYZ”;

chars1[]=”RST”;

chars2[]=”ggg”;

StrReplace(s,s1,s2);

printf(“%s\n”,s);

voidStrReplace(char*strSrc,char*strFind,char*strReplace)

inti=0;

intj;

intn=strlen(strSrc);

intk=strlen(strFind);

N;

I++)

if(*(strSrc+i)==*strFind)

K;

J++

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

当前位置:首页 > 高等教育 > 军事

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

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