华2014校园招聘机试题目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
main函数已隐藏里保留户测试入口里测试实现函数调printf印输出
前方法测试保证终程序正确执行该函数实现意修改改变函数原型定保证编译运行受影响
二题目描述(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 注:格式错误
[cpp] view plaincopyprint
华第题 19191936 17分钟
#include
#include
using namespace std
bool g_flag[26]
void stringFilter(const char *pInputStr long lInputLen char *pOutputStr)
{
assert(pInputStr NULL)
int i 0
if (pInputStr NULL || lInputLen < 1)
{
return
}
const char *p pInputStr
while(*p '\0')
{
if (g_flag[(*p 'a')])
{
p++
}else{
pOutputStr[i++] *p
g_flag[*p 'a'] 1
p++
}
}
pOutputStr[i] '\0'
}
int main()
{
memset(g_flag0sizeof(g_flag))
char input[] abacacde
char *output new char[strlen(input) + 1]
stringFilter(inputstrlen(input)output)
cout<