2012腾讯春季实习生面试经历(一)

时间:2012年4月21号 地点:珞珈山国际宾馆

今天可以说是我第一次参加比较正式的面试,对于缺乏面试经历的我,可谓一次难得的体验机会。

Tencent的面试给我最深刻的影响是比较专业,笔试过后,面试共有三轮,第一二轮为技术面试,第三轮为HR面试。昨天晚上收到了一面通知,一方面很兴奋,终于能有机会见识一下大公司的招聘;另一方面又很忐忑,毕竟没有啥面试经历,没见过场面,也不知道会问些啥问题。

下午14:10,我准时来到宾馆报到。工作人员在查看了名单后,递给我一张写有房间号的纸条,示意我去该房间号等候面试。此次面试,持续了50分钟,内容如下:

1.有一个字串形式为"name1=type1;name2=type2;name3=type3……",请设计一个类,提供接口以实现功能:给定一个name,输出其对应的type类型。个人解答,仅供批斗:

wordParser.h

/*
 *题目:有一个字符串形式为"name1=type1,name2=type2,name3=type3……",
 *请设计一个类,提供接口以实现功能:
 *给定一个name,输出其对应的type类型
 * */
#ifndef WORDPARSER_H
#define WORDPARSER_H
#include <map>
#include <string>
class wordParser {
public:
        wordParser(std::string &s):str(s) { }
        void stringToMap();
        std::string nameSearch(std::string &searchword) const;
private:
        std::string str;
        std::map<std::string, std::string> wordMap;
};      
#endif 

wordParser.cpp

#include <iostream>
#include "wordParser.h"
using namespace std;
 
void wordParser::stringToMap()
{
         string name, type;
         string::size_type pos, lastpos;
         int flag;
 
         if(str == "")
                 return;
 
         pos = 0;
         lastpos = -1;
         flag = 0;
         while((pos = str.find('=', pos)) != string::npos) {
                 name = str.substr(lastpos + 1, pos - lastpos - 1);
 
                 lastpos = pos;
                 if((pos = str.find(',', pos)) != string::npos)
                         type = str.substr(lastpos + 1, pos - lastpos - 1);
                 else {
                         type = str.substr(lastpos + 1, str.length() - lastpos - 1);
                         flag = 1;
                 }
 
                 wordMap.insert(make_pair(name, type));
                 if(flag == 1)
                         break;
 
                 lastpos = pos;
         }
}


string wordParser::nameSearch(string &searchword) const	
{
         string type;
         map<string, string>::const_iterator it = wordMap.find(searchword);
 
         if(it == wordMap.end())
                 type = "";
         else
                 type = it -> second;
 
         return type;
}
 
int main(int argc, char *argv[])
{
         string searchword;
         string type;
 
         if(argc != 2) {
                 cerr << "argument must be 2!" << endl;
                 return 1;
         } 

 
         string str = argv[1];
         wordParser wp(str);
         wp.stringToMap();
 
         cout << "input searchword:(end of ctrl-d)";
         while(cin >> searchword) {
                 if((type = wp.nameSearch(searchword)) != "") {
                        cout << type << endl;
                 }
                 else
                         cout << "cannot find " << searchword << "'s type" << endl;
         }
 
         return 0;
}


运行结果wl@MARS:~/usefulcode/tencent$ ./a.out wulei=male,liu=female,wang=male
input searchword:(end of ctrl-d)wang
male
wulei
male

2.static成员函数的作用是什么?const成员函数的作用是什么?

static成员函数的作用

1)static成员函数没有this指针,通过使用非static成员显示或隐式地引用this是一个编译时错误。

2)static成员函数不是任何对象的组成部分,因而static成员函数不能声明为const。

3)static成员函数也不能声明为虚函数。

const成员函数的作用

1)不能修改类的成员变量,同时不能调用类的非const成员函数

(const成员函数中,this的类型是一个指向const类类型对象的const指针,const成员函数返回*this作为一个const引用)。

2)提供了基于const的重载。const对象只能使用const成员函数。非const对象可以使用任一成员,但非const版本是一个更好的匹配。

3.如何实现线程的同步与互斥?

线程间的同步机制有:

1)互斥锁(一种比较简单的、用于实现线程间对资源互斥访问的机制)

2)条件变量(通常与互斥锁一起使用,单纯的互斥锁用于短期锁定,主要用来保证对临界区的互斥进入。而条件变量则用于线程长期

等待,直至所等待的资源成为可用资源)。

3)信号量机制(可用于多线程OS中)

4.计算武汉的加油站数目?

解题的思路是:看看该地区有多少人口,一般一个家庭拥有多少辆汽车或者多少个家庭拥有一辆车,一般人凭日常常识就知道大概;然后算一算一辆车加油的频率,或者考虑多少人口、多少街区需要一个加油站,最后能得出答案。

posted @ 2012-04-29 23:11  whu-小磊  阅读(176)  评论(0编辑  收藏  举报