欢迎来到天天文库
浏览记录
ID:29843039
大小:45.00 KB
页数:13页
时间:2018-12-24
《华为校园招聘笔试算法题汇总》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、华为笔试算法题汇总1.通过键盘输入一串小写字母(a~z)组成的字符串。请编写一个字符串过滤程序,若字符串中出现多个相同的字符,将非首次出现的字符过滤掉。比如字符串“abacacde”过滤结果为“abcde”。要求实现函数:voidstringFilter(constchar*pInputStr,longlInputLen,char*pOutputStr);【输入】pInputStr: 输入字符串 lInputLen: 输入字符串长度 【输出】pOutputStr:输出字符串,空间已经
2、开辟好,与输入字符串等长; 【注意】只需要完成该函数功能算法,中间不需要有任何IO的输入输出示例 输入:“deefd” 输出:“def”输入:“afafafaf” 输出:“af”输入:“pppppppp” 输出:“p”main函数已经隐藏,这里保留给用户的测试入口,在这里测试你的实现函数,可以调用printf打印输出当前你可以使用其他方法测试,只要保证最终程序能正确执行即可,该函数实现可以任意修改,但是不要改变函数原型。一定要保证编译运行不受影响[cpp]viewplaincopy//////
3、////////////////////////////////////////////////////////////////////#include #include using namespace std; bool g_flag[26]; void stringFilter(const char *pInputStr, long lInputLen, char *pOutputStr) { assert(pInp
4、utStr != NULL); int i = 0; if (pInputStr == NULL
5、
6、 lInputLen <= 1) { return; } const char *p = pInputStr; while(*p != ' ') { if (g_flag[(*p - 'a')]) { p++; }else{ pOut
7、putStr[i++] = *p; g_flag[*p - 'a'] = 1; p++; } } pOutputStr[i] = ' '; } int main() { memset(g_flag,0,sizeof(g_flag)); char input[] = "abacacde"; char *output = new char[strlen(input) + 1];
8、 stringFilter(input,strlen(input),output); cout<9、为"字符重复的次数+字符"。例如:字符串"xxxyyyyyyz"压缩后就成为"3x6yz"。要求实现函数: voidstringZip(constchar*pInputStr,longlInputLen,char*pOutputStr);【输入】pInputStr: 输入字符串 lInputLen: 输入字符串长度【输出】pOutputStr:输出字符串,空间已经开辟好,与输入字符串等长;【注意】只需要完成该函数功能算法,中间不需要有任何IO的输入输出示例 输入:“cccddecc” 输出:“310、c2de2c”输入:“adef” 输出:“adef”输入:“pppppppp”输出:“8p”[cpp]viewplaincopy////////////////////////////////////////////////////////////////////////// #include #inclu
9、为"字符重复的次数+字符"。例如:字符串"xxxyyyyyyz"压缩后就成为"3x6yz"。要求实现函数: voidstringZip(constchar*pInputStr,longlInputLen,char*pOutputStr);【输入】pInputStr: 输入字符串 lInputLen: 输入字符串长度【输出】pOutputStr:输出字符串,空间已经开辟好,与输入字符串等长;【注意】只需要完成该函数功能算法,中间不需要有任何IO的输入输出示例 输入:“cccddecc” 输出:“3
10、c2de2c”输入:“adef” 输出:“adef”输入:“pppppppp”输出:“8p”[cpp]viewplaincopy////////////////////////////////////////////////////////////////////////// #include #inclu
此文档下载收益归作者所有