视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
2013华为校园招聘机试题_南航版
2025-09-25 17:56:20 责编:小OO
文档
0903)2013华为校园招聘机试题

一、题目描述(60分):

通过键盘输入一串小写字母(a~z)组成的字符串。请编写一个字符串过滤程序,若字符串中出现多个相同的字符,将非首次出现的字符过滤掉。

比如字符串“abacacde”过滤结果为“abcde”。

要求实现函数: 

void stringFilter(const char *pInputStr, long lInputLen, char *pOutputStr);

【输入】 pInputStr:  输入字符串

         lInputLen:  输入字符串长度         

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

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

示例 

输入:“deefd”        输出:“def”

输入:“afafafaf”     输出:“af”

输入:“pppppppp”     输出:“p”

二、题目描述(40分):

通过键盘输入一串小写字母(a~z)组成的字符串。请编写一个字符串压缩程序,将字符串中连续出席的重复字母进行压缩,并输出压缩后的字符串。

压缩规则:

1. 仅压缩连续重复出现的字符。比如字符串"abcbc"由于无连续重复字符,压缩后的字符串还是"abcbc".

2. 压缩字段的格式为"字符重复的次数+字符"。例如:字符串"xxxyyyyyyz"压缩后就成为"3x6yz"

要求实现函数: 

void stringZip(const char *pInputStr, long lInputLen, char *pOutputStr);

【输入】 pInputStr:  输入字符串

         lInputLen:  输入字符串长度         

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

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

示例 

输入:“cccddecc”   输出:“3c2de2c”

输入:“adef”     输出:“adef”

输入:“pppppppp” 输出:“8p”

三、题目描述(50分): 

通过键盘输入100以内正整数的加、减运算式,请编写一个程序输出运算结果字符串。

输入字符串的格式为:“操作数1 运算符 操作数2”,“操作数”与“运算符”之间以一个空格隔开。

补充说明:

1. 操作数为正整数,不需要考虑计算结果溢出的情况。

2. 若输入算式格式错误,输出结果为“0”。

要求实现函数: 

void arithmetic(const char *pInputStr, long lInputLen, char *pOutputStr);

【输入】 pInputStr:  输入字符串

         lInputLen:  输入字符串长度         

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

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

示例 

输入:“4 + 7”  输出:“11”

输入:“4 - 7”  输出:“-3”

输入:“9 ++ 7”  输出:“0” 注:格式错误

实现:其中第三题写的有些别扭,主要是额外的存储空间,三个函数测试通过了

#include

#include

//过滤函数

void stringFilter(const char *pInputStr, char *pOutputStr)

{

int a[26] = {0};

const char* pstr = pInputStr;

char* pResult = pOutputStr;

while( *pstr != '\\0')

{

a[*pstr - 'a']++;

if(a[*pstr - 'a'] > 1)

{

pstr++;

}

else

{

*pResult = *pstr;

pstr++;

pResult++;

}

}

*pResult = '\\0';

}

//压缩字符串

void stringZip(const char *pInputStr, long lInputLen, char *pOutputStr)

{

const char* pFirst = pInputStr;

const char* pSecond = pInputStr+1;

char* pResult = pOutputStr;

int count = 0;

while(*pSecond != '\\0')

{

if(*pSecond == *pFirst)

{

count++;

}

else

{

if(count > 0)

{

*pResult++ = count+1 + '0';

}

*pResult++ = *pFirst;

count = 0;

}

pFirst++;

pSecond++;

}

if(count > 0)

{

*pResult++ = count+1 + '0';

}

*pResult++ = *pFirst;

*pResult = '\\0';

}

void arithmetic(const char *pInputStr, long lInputLen, char *pOutputStr)

{

char* pTemp = (char*)malloc(lInputLen);

char* pLeft = pTemp;

const char* pRight = pInputStr;

while(*pInputStr != '\\0')

{

if(*pInputStr == '+' || *pInputStr == '-')

{

pRight = pInputStr + 1;

break;

}

else

{

*pTemp++ = *pInputStr++;

}

}

*pTemp = '\\0';

if (pRight == pLeft || *pRight == '+' || *pRight == '-')

{

*pOutputStr++='0';

*pOutputStr = '\\0';

return;

}

int L = atoi(pLeft);

int R = atoi(pRight);

int result;

switch (*pInputStr)

{

case '+':

result = L + R;

break;

case '-':

result = L - R;

break;

default:

result = 0;

break;

}

itoa(result, pOutputStr, 10);

}

int main()

{

//char a[] = "youyouare";

//char a1[] = "deefd";

//char a2[] = "afafafaf";

//char a3[] = "ppppp";

//char* b = (char*)malloc(100);

//char* b1 = (char*)malloc(100);

//char* b2 = (char*)malloc(100);

//char* b3 = (char*)malloc(100);

//

//stringFilter(a,b);

//stringFilter(a1,b1);

//stringFilter(a2,b2);

//stringFilter(a3,b3);

//char t1[] = "cccddecc";

//char t2[] = "deefd";

//char t3[] = "pppppp";

//char rt1[15], rt2[15], rt3[15];

//stringZip(t1,0,rt1);

//stringZip(t2,0,rt2);

//stringZip(t3,0,rt3);

char s1[] = "4+7";

char s2[] = "4-7";

char s3[] = "9++7";

char st1[15], st2[15], st3[15];

arithmetic(s1, strlen(s1), st1);

arithmetic(s2, strlen(s2), st2);

arithmetic(s3, strlen(s3), st3);

}下载本文

显示全文
专题