接上面的文章

人有耐心很毅力,在以后的工作中也是好的合作者。题一定要做完,表现出认真的态度,若有疑问或卡壳,还可以寻求面试官的帮助,这些不会减分,相反,会增加你和他们的接触机会,面试官会评估你的沟通能力。
有一次,有1个人来面试,题没有完全ok,但很规范,态度很认真,他把他知道的都做上去了,我给了他技术类的高分。后来,顺利进入公司,再后来进步很快,成了重要角色。
若文章对你有帮助的话,请在此讨论。
祝你成功
面试题
1.链表和数组的区别在哪里?
2.编写实现链表排序的一种算法。说明为什么你会选择用这样的方法?
3.编写实现数组排序的一种算法。说明为什么你会选择用这样的方法?
4.请编写能直接实现strstr()函数功能的代码。
5.编写反转字符串的程序,要求优化速度、优化空间。
6.在链表里如何发现循环链接?
7.给出洗牌的一个算法,并将洗好的牌存储在一个整形数组里。
8.写一个函数,检查字符是否是整数,如果是,返回其整数值。(或者:怎样只用4行代码 ,编写出一个从字符串到长整形的函数?)
9.给出一个函数来输出一个字符串的所有排列。
10.请编写实现malloc()内存分配函数功能一样的代码。
11.给出一个函数来复制两个字符串A和B。字符串A的后几个字节和字符串B的前几个字节重叠。
12.怎样编写一个程序,把一个有序整数数组放到二叉树中?
13.怎样从顶部开始逐层打印二叉树结点数据?请编程。
14.怎样把一个链表掉个顺序(也就是反序,注意链表的边界条件并考虑空链表)?
另外:
一、单项选择题:(共12题,每题2分,共24分)
1. 下面哪一个不是C++的标准数据类型? ( D)
A. int B. char
C. bool D. real
2. break关键字在哪一种语法结构中不能使用? (C)
A. for语句 B. switch语句
C. if语句 D. while语句
3. 类的继承方式有几种? (B )
A. 两种 B. 三种
C. 四种 D. 六种
4. extern关键字的作用是什么? (D)
A. 声明外部链接 B. 声明外部头文件引用
C. 声明使用扩展C++语句 D. 声明外部成员函数、成员数据。
5. C库函数strstr的功能是? (A )
A. 查找子串 B. 计算字符串长度
C. 字符串比较 D. 连结字符串
6. stl::deque是一种什么数据类型? (A )
A. 动态数组 B. 链表
C. 堆栈 D. 树
7. STL库里含有下面的哪一种泛型算法? (D )
A. KMP查找 B. 折半查找
C. 冒泡排序 D. 快速排序
8. 现在最快且最通用的排序算法是什么? (A )
A. 快速排序 B. 冒泡排序
C. 选择排序 D. 外部排序
9. Win32下的线程的哪一种优先级最高? ( C)
A. THREAD_PRIORITY_HIGHEST 高优先级
B. THREAD_PRIORITY_IDLE 最低优先级,仅在系统空闲时执行
C. THREAD_PRIORITY_TIME_CRITICAL 最高优先级
D. THREAD_PRIORITY_ABOVE_NORMAL 高于普通优先级
10. 下面四个选项中,哪一个不是WinMain函数的参数? (D )
A. HINSTANCE B. INT
C. LPSTR D. WPARAM
11. VC++的编译器中,运算符new底层的实现是什么? (B )
A. VirtualAlloc() B. HeapAlloc()
C. GlobalAlloc() D. AllocateUserPhysicalPages()
12. 下面哪一本C++参考书最厚? ( C)
A. 《Think in C++》 B. 《深入浅出MFC》
C. 《C++ Primer》 D. 《Effective C++》
13. 当调用Windows API函数InvalidateRect,将会产生什么消息(A)
A. WM_PAINT B. WM_CREATE
C. WM_NCHITTEST D. WM_SETFOCUS
14. 关于virtual void Draw()=0,下面说法正确的有几个(C)
(1)它是纯虚函数(对)
(2)它在定义它的类中不能实现(对)
(3)定义它的类不可实例化(对)
(4)如果一个类要继承一个ADT类,必须要实现其中的所有纯虚函数(错)//可以不实现,派生之后的类仍旧作为一个抽象类.
A. 1 B. 2
C. 3 D. 4
二、不定项选择题:(共6题,每题3分,共18分,多选、错选、漏选均不给分)
1. vector::iterator重载了下面哪些运算符? (ACD)
A. ++ B. >>
C. *(前置) D. ==
2. CreateFile( )的功能有哪几个? (AB )
A. 打开文件 B. 创建新文件
C. 文件改名 D. 删除文件
3. 下面哪些是句柄(HANDLE)? (ABCD )
A. HINSTANCE 实例句柄B. HWND 窗口句柄
C. HDC 设备描述符号句柄 D. HFONT 字体句柄
4. 下面哪些不是OpenGL标准几何元素的绘制模式? (A )
A. GL_FOG B. GL_LINE_STRIP
C. GL_POINTS D. GL_TRIANGLE_FAN
5. 下面哪些运算符不能被重载? (ABD )
A. 做用域运算符“::” B. 对象成员运算符“.”
C. 指针成员运算符“->” D. 三目运算符“? :”
6. 下面哪些人曾参与了世界上第一个C++编译器的开发? ( )
A. Bill Gates B. Stanley Lippman
C. Anderson Hejlsberg D. Bjarne Stroustrup
7. 以下说法正确的是? ( ABC)
A. 头文件中的 ifndef/define/endif 是为了防止该头文件被重复引用。
B. 对于#include <filename.h> ,编译器从标准库路径开始搜索 filename.h
对于#include “filename.h” ,编译器从用户的工作路径开始搜索 filename.h
C. C++语言支持函数重载,C语言不支持函数重载。函数被C++编译后在库中的名字与C 语言的不同。假设某个函数的原型为: void foo(int x, int y); 该函数被C编译器编译后在库 中的名字为_foo,而C++编译器则会产生像_foo_int_int之类的名字。C++提供了C连接交换指定符号extern“C”来解决名字匹配问题。
D. fopen函数只是把文件目录信息调入内存。//错,fopen是把整个文件读入内存
三、填空题:(共8题,每题3分,共24分)
1. 一个大小为320 X 192,颜色为灰度索引色的设备相关位图有______字节。如果此位图颜色为24位真彩色,则它的大小有______字节。
2. Windows API的中文意义是____ windows应用程序接口___。
3. 计算反正弦的库函数是__asin()____;计算浮点数绝对值的库函数是__fabs()____;计算浮点数n次方的库函数是__pow()____;将浮点数转化为字符串的库函数是___fcvt()___。
4. 如果i等于5,那么( ++i ) - -的返回值是__6__。
5. API LoadBitmap()的功能是从__指定的模块和或应用程序实例__中读取位图数据到内存。
6. new和__delete___对应,malloc和_free___对应,他们之间_ 不能__交叉混用。calloc的功能是__为数组动态分配内存___,realloc的功能是_改变原有内存区域的大小_。
7. SendMessage和PostMessage都会向窗体发送一个消息,但SendMessage__将一条消息发送到指定窗口,立即处理__而PostMessage__将一条消息投递到指定窗口的消息队列,不需要立即处理___。
8. 输出指定圆心、半径、边数的圆上的点:
const int nCount = 12;
const double dOrgX = 5.0,
dOrgY = 3.0;
const double dRadius = 2.0;
for( int i = 0; i < nCount; i++ )
{
double dAngle = M_PI * 2.0 / (double)nCount * i;
cout << "第" << i << "点:X = " << ________; cout << ", Y = " << __________ << endl;
}
三、判断题:(共12题,每题2分,共24分)
1. 一个类必须要有一个不带参数的构造函数。 错
2. 你不能写一个虚的构造函数。 对
3. 类里面所有的函数都是纯虚函数时才是纯虚类。 错
4. const成员函数对于任何本类的数据成员都不能进行写操作。 对
5. 函数中带默认值的参数必须位于不带默认值的参数之后。 对
6. char *p = "Test"; p[0] = 'R'; 错
7. cout << "Test"; 对
8. stl::list不支持随机访问叠代器。 对
9. stl::vector的效率比stl::list高。 错
10. VC和VC++是一回事,而VC++是一种比C++更难一些的语言。 错
11. 理论上,new和malloc造成的内存泄露都会由操作系统回收。 错
12. 在C++中struct和class的差别很大,所以从语法上不能混用。对
四、简述题(共3题,每题5分,共15分)
1. 请简述PeekMessage和GetMessage的区别。
答: Peekmessage和Getmessage都是向系统的消息队列中取得消息,两个函数的不同在于取不到消息的时候,若Getmessage()向消息队列中取不到消息,则程序的主线程会被OS(操作系统)挂起,等到有合适的消息时才返回;若是用Peekmessage()在消息队列中取不到消息,则程序会取得OS控制权,运行一段时间。
另外,在处理消息的时候,GetMessag()会将消息从队列中删除,而PeekMessage()可以设置最后一个参数wRemoveMsg来决定是否将消息保留在队列中。
2. 请列出你所知道的在Windows SDK平台上,实现计时功能的方法。
答:可以使用SetTimer函数创建一个计时器,SetTimer的函数原型如下:
UINT_PTR SetTimer( HWND hWnd, UINT_PTR nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc
3. 请简述你所知道的const的各种用法。
答: const 常量
const 修饰类的数据成员
const 修饰指针
const 应用在函数声明中
const 应用在类成员函数
五、编程题:(共3题,第1小题7分,第2小题14分,第3小题24分)
1. 深度遍历二叉树。
struct Node
{
Node *Parent;

Node *Left, *Right;

};
void Through(Node *Root)
{
}
2. 二分法查找。

int DicFind( int *Array, int Count, int Value )
{

}
3. 写出字符串类String的默认构造函数、析构函数和重载赋值运算符。
已知类String的原型为:
class String
{
public:
String( const char *pStr = NULL ); // 默认构造函数
~String( void ); // 析构函数
String &operate = ( const String &Source ); // 重载赋值运算符
private:
char *m_pData; // 指向字符串的指针
};


今天下午的两道面试题
1。 一人岁数的3次方是四位数,四次方是六位数,并知道此人岁数的3次方和4次方用遍了0~9十个数字。编写一程序求此人的岁数。

2。对1,2,3, 4, 5 这五个数任意取出两个数,列出他们的所有组合。
public static int getAge() {
int age;
int third;
int fourth;

for (int i = 11; true; i++) {
if (i < 200) {
third = (int) Math.pow(i, 3);
fourth = (int) Math.pow(i, 4);
if (getLength(third, fourth) == 10) {
age = i;
break;
}

}
}
return age;
}

public static int getLength(int args1, int args2) {
String str1 = String.valueOf(args1);
String str2 = String.valueOf(args2);
String str = str1 + str2;
if (str.length() != 10) {
return -1;
}
int[] intarray = new int[10];
for (int i = 0; i < str.length(); i++) {
intarray[i] = Integer.parseInt(str.substring(i,i+1));
}
Arrays.sort(intarray);
if(intarray[0]!=0 && intarray[9]!=9)
return -1;

return 10;
}
第二题还更简单了

for(int i=1; i<6; i++){
for(int j=1; j<6; j++){
if(i==j){
System.out.println(j+""+j);
}else{
System.out.println(i+""+j);
System.out.println(j+""+i);
}
}
}
public class A {
// http://community.csdn.net/Expert/topic/4667/4667929.xml?temp=.57922
public static void main(String[] args) {
String t;
String[] s = new String[5];
int j = s.length;
for(int i=0; i<j; i++) {
s[i] = new Integer(i+1).toString();
}

for(int i=0; i<j; i++) {
t = s[i];
for(int a=0; a<j; a++) {
t += s[i];
System.out.println(t);
}
System.out.println();
}
}
}
第二题还更简单了

for(int i=1; i<6; i++){
for(int j=1; j<6; j++){
if(i==j){
System.out.println(j+""+j);
}else{
System.out.println(i+""+j);
System.out.println(j+""+i);
}
}
}
============================================================
楼上的没看清题目,它是让你对1,2,3, 4, 5 这五个数任意取出两个数,列出他们的所有组合,所以重复的数字不应该算在里面。
第二题应该改为:
for(int i=1; i<6; i++){
for(int j=1; j<6; j++){
if(i==j){
break;
}else{
System.out.println(i+""+j);
System.out.println(j+""+i);
}
}
}
public class B {
public static void main(String[] args) {
for (int i = 1; i < 6; i++) {
int t = i;
for(int a = 0; a<5; a++) {
int c = a+1;
if(c == t) {
continue;
}else {
System.out.println(t*10+c);
}
}
System.out.println();
}
}
}
第二题
public class Test
{
public static void main(String[] args)
{
int[][] a=new int[5][];
for(int i=0;i<a.length;i++)
{
a[i]=new int[i+1];
}
for(int i=1;i<=a.length;i++)
{

for(int j=i+1;j<=a.length;j++)
{
System.out.print(i);
System.out.print(j+" ");
}
System.out.print(" ");
}

for(int i=a.length;i>0;i--)
{

for(int j=i-1;j>0;j--)
{
System.out.print(i);
System.out.print(j+" ");
}
System.out.print(" ");
}
}
}


public class Test {

public static int getDigits(String str) {
int[] intarr = new int[10];
for (int i = 0; i < 10; i++)
intarr[i] = 0;
for (int i = 0; i < str.length(); i++) {
int j = Integer.parseInt(str.substring(i, i + 1));
intarr[j] = 1;
}
int num = 0;
for (int i = 0; i < 10; i++)
num = num + intarr[i];
return num;
}

private static int getAge() {
int age;
int third;
int fourth;
for (age = 1; age < 100; age++) {
third = (int) Math.pow(age, 3);
fourth = (int) Math.pow(age, 4);
if (third < 1000 || third >= 10000)
continue;
if (fourth < 100000 || fourth >= 1000000)
continue;
String str = String.valueOf(third) + String.valueOf(fourth);
if (getDigits(str) == 10)
return age;
}
return 0;
}
}

第二道题
class Combine
{
public static void main(String[] args)
{
for(int i=1; i<5; i++)
{
for(int j=i+1; j<6; j++)
{
System.out.println(i+""+j);
System.out.println(j+""+i);
}
}
}
public class Age
{
public static void main(String [] args)
{
String str1 = null;
String str2 = null;
String str3 = null;
String str4 = "0123456789";
for(int i=10;i<50;i++)
{
str1 = Integer.toString(i*i*i);
str2 = Integer.toString(i*i*i*i);
str3 = str1+str2;
if((str1.length() == 4) && (str2.length() ==6))
{
boolean flag = true;
for(int j=0;j<10;j++)
if(str3.indexOf(str4.charAt(j))==-1)
flag = false;
if(flag){
System.out.println(">>>"+i);
System.out.println(str3);
}
}
}

}
}

比赛贴~微软又一道笔试题
silver6 | 04 四月, 2006 09:48
怎样只用4行代码编写出一个从字符串到长整形的转换函数?
我的方法,不过好象比4行多 *_#!~
long atol(char *str)
{
char c = *str;
if( !isdigit(c) ) str++;
for(long value = 0; *str != ''; value = value * 10 + (*str -'0'),str++);
return c == '-' ? -value : value ;
}
void stol(const char * des, long& num)
{
for (int base = 1, i = 0; des[i] != ''; base = 10, ++i)
{
num *= base;
num += (int)(des[i] - '0');
}
}
num 要初始化为0

void stol(const char * des, long& num)
{
for (int i=num=0; des[i] != ''; i++)
{
num *= 10;
num += (int)(des[i] - '0');
}
}

void stol(char *str, long &num)
{
while(*str != '')
{
num = num * 10 + (*str - '0');
str++;
}
}
void stol(const char * des, long& num)
{
char p = des[0];
for (int b = 1, pos = 1, base = 1; des[pos] != ''; b = 10, ++pos, base *= 10)
{
(num *= b) += (int)(des[pos] - '0');
}
p == '-' ? (num *= -1) : (num = (int)(des[0] - '0') * base + num);
}
改了一下
真的是微软的笔试题么?
我只用了一行。
#include <iostream>
using namespace std;

long str2long(char* p,long xxx=0L)
{
return *p==''?xxx:str2long(p,xxx*10+(*p+++0-'0'));
}

int main()
{
char *str="123456789",*p=str;
cout<<str2long(p);
getchar();
return 0;
}
用STL,四行
#include <sstream>
#include <iostream>
#include <string>

using namespace std;

long ToLong(string& s)
{
long l;
istringstream iss(s);
iss>>l;
return l;
}
int main(int argc, _TCHAR* argv[])
{
string s = "-12356";
cout<<ToLong(s);
return 0;
}
谢谢刚才上面的帖子提醒负数的问题,我更正了,还是只用一行:
#include <iostream>
using namespace std;

long str2long(char* p,long xxx=0L,bool IsPositive=true)
{
return *p==''?(IsPositive?xxx:xxx*(-1)):(*p=='-'?str2long(++p,0L,false):str2long(p,xxx*10+*p+++0-'0',IsPositive));
}

int main()
{
char *str="-123456789",*p=str;
cout<<str2long(p);
getchar();
return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值