华为面向2013年招聘笔试题
笔试题目(机试,共两题)
题目一:子串分离
题目描述:
通过键盘输入任意一个字符串序列,字符串可能包含多个子串,子串以空格分隔。请编写一
个程序,自动分离出各个子串,并使用’,’将其分隔,并且在最后也补充一个’,’并将子
串存储。
如果输入“abc def gh i d”,结果将是abc,def,gh,i,d,
要求实现函数:
void DivideString(const char *pInputStr, long lInputLen, char *pOutputStr);
【输入】 pInputStr: 输入字符串
lInputLen: 输入字符串长度
【输出】 pOutputStr: 输出字符串,空间已经开辟好,与输入字符串等长;
【注意】只需要完成该函数功能算法,中间不需要有任何IO 的输入输出
示例
输入:“abc def gh i d”
输出:“abc,def,gh,i,d,”
题目二:逆序链表输出。
题目描述:
将输入的一个单向链表,逆序后输出链表中的值。链表定义如下:
typedef struct tagListNode
{
int value;
struct tagListNode *next;
}ListNode;
要求实现函数:
void converse(ListNode **head);
【输入】head: 链表头节点,空间已经开辟好
【输出】head: 逆序后的链表头节点
【返回】无
笔试题目(机试,共两题)
题目一:子串分离
题目描述:
通过键盘输入任意一个字符串序列,字符串可能包含多个子串,子串以空格分隔。请编写一
个程序,自动分离出各个子串,并使用’,’将其分隔,并且在最后也补充一个’,’并将子
串存储。
如果输入“abc def gh i d”,结果将是abc,def,gh,i,d,
要求实现函数:
void DivideString(const char *pInputStr, long lInputLen, char *pOutputStr);
【输入】 pInputStr: 输入字符串
lInputLen: 输入字符串长度
【输出】 pOutputStr: 输出字符串,空间已经开辟好,与输入字符串等长;
【注意】只需要完成该函数功能算法,中间不需要有任何IO 的输入输出
示例
输入:“abc def gh i d”
输出:“abc,def,gh,i,d,”
题目二:逆序链表输出。
题目描述:
将输入的一个单向链表,逆序后输出链表中的值。链表定义如下:
typedef struct tagListNode
{
int value;
struct tagListNode *next;
}ListNode;
要求实现函数:
void converse(ListNode **head);
【输入】head: 链表头节点,空间已经开辟好
【输出】head: 逆序后的链表头节点
【返回】无
【注意】只需要完成该函数功能算法,中间不需要有任何IO 的输入输出
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void DivideString(const char *pInputStr, long lInputLen, char *pOutputStr)
{
/* int cnt = 0;
for(int i=0;i<lInputLen;i++)
{
if(pInputStr[i]!=' ')
{ cnt = 0;
*pOutputStr++ = pInputStr[i];
}
else
{ cnt++;
if(cnt==1)
*pOutputStr++ = ',';
}
}
*pOutputStr++ = ',';
*pOutputStr = '\0';
*/
int cnt;
while(*pInputStr)
{
if(*pInputStr!=' ')
{ cnt = 0;
*pOutputStr++ = *pInputStr++;
}
else
{ cnt++;
pInputStr++;
if(cnt==1)
*pOutputStr++ = ',';
}
}
*pOutputStr++ = ',';
*pOutputStr = '\0';
}
void main()
{
char *str = "abc def gh i d";
int len = strlen(str);
char *outstr = (char*)malloc(sizeof(str));
//char outstr[100];
DivideString(str,len,outstr);
printf("%s",outstr);
printf("\n");
}