![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
面试题
auvKone
未知攻,焉知防
展开
-
atoi实现
typedef unsigned long ULONG;#define INT_MAX 2147483647L#define INT_MIN (-2147483647-1L)int my_atoi(const char *p){ ULONG res = 0, digit; int sign = 1; while(isspace(*p))p++; if(原创 2013-12-25 22:45:26 · 569 阅读 · 0 评论 -
不使用加减乘除,求一个数的7倍
C/C++面试题#include using namespace std;int bit_add(int a, int b){ int carry = a & b; int noCarrySum = a ^ b; if (carry) return bit_add(carry << 1, noCarrySum); else原创 2015-07-04 15:50:47 · 2890 阅读 · 1 评论 -
找出字符串中第1个只出现1次的字符
C/C++面试题,使用256大小的表,扫描两遍,第一遍统计每个字符的个数,第二遍找到第1个只出现一次的字符。注意:1.str为NULL时,返回\0;2.找不到第1个只出现1次的字符时,返回\0;3.table不要忘记初始化为全0。char find_first_not_repeat_char(char *str){ if (str == NULL) r原创 2015-07-04 18:11:50 · 1041 阅读 · 0 评论 -
C语言实现itoa
注意:1. 有可能是0或是负数。void itoa(int a, char str[]){ char *beg = str; int sign; if ((sign = a) < 0) a = -a; do{ *str++ = '0' + a % 10; }while((a /= 10) > 0); if (sign <原创 2015-07-04 16:23:44 · 2845 阅读 · 0 评论 -
C++常见笔试题
Q. 下面程序的输出结果是?class A{ public: A(){ cout << "A()" << endl; } ~A(){ cout << "~A()" << endl; } virtual void fun(){原创 2015-06-02 14:54:48 · 753 阅读 · 0 评论 -
C++常见面试问题
Q1:构造函数可以是虚函数吗?为什么?A1:不可以。从实现上,虚函数是使用虚表指针,而虚表指针存在于对象的内存空间中,而在构造函数调用之前,对象内存空间还没有分配,所以不存在使用虚表指针调用构造函数。从使用角度上,虚函数的作用在于通过父类的指针或者引用来调用它的时候能够变成调用子类的那个成员函数。而构造函数是在创建对象时自动调用的,不可能通过父类的指针或者引用去调用。原创 2015-05-28 14:09:34 · 510 阅读 · 0 评论 -
链表面试题
struct ListNode{ int m_nKey; ListNode *m_pNext;};Q1:单链表反转。Q2:检测单链表是否有环,如果有环的话,找到环的入口点。Q3:检测两个单链表是否相交,如果相交,返回相交节点。Q4:从尾到头输出链表。Q5:在O(1)时间删除链表节点。Q6:只给定单链表中某个非空节点p,原创 2015-05-28 14:06:53 · 553 阅读 · 0 评论 -
高进度计算C++实现
大整数的加减乘除:大整数加法,openjudge 2981void add(string &s1, string &s2, string &res){ if (s1.size() < s2.size()){ s1.insert(0, s2.size() - s1.size(), '0'); } else { s2.insert(0,原创 2015-04-26 15:33:28 · 868 阅读 · 0 评论 -
给定数量不限的硬币,币值为25分、10分、5分和1分,编写代码计算n分有多少种表示法。
递归问题int makeChange(int n, int denom){ int next_denom; switch(denom){ case 25: next_denom = 10; break; case 10: next_denom = 5;原创 2014-02-09 15:04:17 · 3874 阅读 · 0 评论 -
编写一个方法,返回某集合的所有子集。
#include #include using namespace std;vector > getSubsets(const set &iset){ vector > allsubsets; allsubsets.push_back(set()); for(set::const_iterator i = iset.begin(); i != iset.en原创 2014-02-08 22:23:07 · 1635 阅读 · 0 评论 -
编写一个方法,返回某字符串的所有排列组合。
简单构造法:n=1时,S=a1, 只有字符串a1;n=2时,S=a1a2,有2种排列组合,a1a2,a2a1n=3时,S=a1a2a3,排列组合为,a3a1a2, a1a3a2, a1a2a3, a3a2a1, a2a3a1, a2a1a3根据f(n-1)求f(n),将an插入到f(n-1) 的所有字符串的任意位置。C++实现:#include #include原创 2014-02-09 10:17:01 · 2461 阅读 · 0 评论 -
MySQL增删改查
MySQL面试之CRUD(增删改查)#创建表create table employee(id int unsigned primary key auto_increment,name varchar(32) not null,salary double not null);#查看创建表show create table employee;#插入1条记录原创 2015-07-05 22:21:29 · 484 阅读 · 0 评论