2013华为招聘笔试题目

时间:2017-05-21 笔试题目 我要投稿

  题目描述:

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

  个程序,自动分离出各个子串,并使用’,’将其分隔,并且在最后也补充一个’,’并将子

  串存储。

  如果输入“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,”

  参考答案:

  #include

  #include

  #define NULL 0

  #define ERROR 0

  void DivideString(const char *pInputStr,long inputLen,char *pOutputStr)

  {

  int i=0,j=0;

  for(i=0,j=0;i

  {

  if(pInputStr[i]!=' ')

  pOutputStr[j]=pInputStr[i];

  else

  {

  pOutputStr[j]=',';

  i++;

  while(pInputStr[i]==' ')

  i++;

  i--;

  }

  }

  pOutputStr[j]=',';

  pOutputStr[++j]='\0';

  }

  int main()

  {

  char *pInputStr;

  char *pOutputStr;

  int inputLen=13;

  pInputStr=(char*)malloc(inputLen*sizeof(char));

  pInputStr="abc def ghi d";

  if(pInputStr==NULL)

  return ERROR;

  pOutputStr=(char*)malloc((inputLen+1)*sizeof(char));

  if(pOutputStr==NULL)

  return ERROR;

  DivideString(pInputStr,inputLen,pOutputStr);

  cout<

  }

  }

  题目二:逆序链表输出。

  题目描述:

  将输入的一个单向链表,逆序后输出链表中的值。链表定义如下:

  typedef struct tagListNode

  {

  int value;

  struct tagListNode *next;

  }ListNode;

  要求实现函数:

  void converse(ListNode **head);

  【输入】head: 链表头节点,空间已经开辟好

  【输出】head: 逆序后的链表头节点

  【返回】无

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

2013华为招聘笔试题目相关推荐
热门推荐