BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #41642同步于 2010/7/21
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

两道面试题,看看各位有何高见

panda
2010/7/21镜像同步10 回复
The work should consider performance and maintainability! 第一题 Write a method to determine if a given string is a palindrome. E.g. "Madam I'm Adam", or "A man, a plan, a canal, Panama". The prototype for the function is: bool is_palindrome(char const * str) a) Provide an implementation for this function in C/C++. b) What assumptions does your code make? 第二题 Write a method to remove consecutive items with duplicate data values from a singly linked list. The method should return the number of items removed. The method should clean up memory as required, and should assume that memory was allocated using new. For example, passing in the list ->a->b->c->c->a->b->b->b->a->null should result in ->a->b->c->a->b->a->null and return 3 The list item definition and function declaration are given below struct litem { char data; litem* next; }; int remove_consecutive_duplicates( litem*& list ); a) Provide an implementation for this function in C/C++. b) What assumptions does your code make?
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
nickluchen机器人#1 · 2010/7/21
第一题是回文啊,在《C专家编程》上提到过。不过我没写过。 好像书上提到的程序是生成一段回文,越长越好。书上的例句好像写了一页。 第二个应该比较简单吧,注意先修改指针再释放节点占的内存
panda机器人#2 · 2010/7/21
我觉得第二题难就难在它所谓的performance和maintainability,总让人觉得没有最好的写法只有更好的写法。。。 【 在 nickluchen 的大作中提到: 】 : 第一题是回文啊,在《C专家编程》上提到过。不过我没写过。 : 好像书上提到的程序是生成一段回文,越长越好。书上的例句好像写了一页。 : 第二个应该比较简单吧,注意先修改指针再释放节点占的内存 : ...................
a206206机器人#3 · 2010/7/21
第一个是判断是否是回文?还是说找出一个方法写出回文?
panda机器人#4 · 2010/7/21
判断是否是回文 【 在 a206206 的大作中提到: 】 : 第一个是判断是否是回文?还是说找出一个方法写出回文? : -- : 黑暗凝集灵魂,堕落方能自由 : ...................
buptxrc机器人#5 · 2010/7/21
判断是否是回文是不是千万别用递归。。。。?
panda机器人#6 · 2010/7/21
各位可以考虑把程序写出来,有时候写程序的时候,才会发现一个题精彩的地方,呵呵
RaulSpain007机器人#7 · 2010/7/22
【 在 panda 的大作中提到: 】 : 各位可以考虑把程序写出来,有时候写程序的时候,才会发现一个题精彩的地方,呵呵 判断回文有啥速率要求么?感觉这个要写出来并不是很难把?还是我想简单了?
fuqiang机器人#8 · 2010/7/23
第一题 #include<string.h> #include<iostream.h> bool is_palindrome(char const * str){ char str[];//需要判断的字符串 int i=0; int max;//最长字符 for(i=0;i<num;i++){ cout<<"输入第"<<(i+1)<<"个字符"<<endl; cin>>str[i]; } int k=0; int n=i/2; bool m=1; for(k=0;k<=n;k++){ if(str[k]!=str[i-k]){ m=0 break; } return m; }
Wing机器人#9 · 2010/7/23
ls是初学C++?