Careercup | Chapter 8
8.2 Imagine you have a call center with three levels of employees: respondent, manager, and director. An incoming telephone call must be first allocated to a respondent who is free. If the respondent can't handle the call, he or she must escalate the call to a manager. If the manager is not free or notable to handle it, then the call should be escalated to a director. Design the classes and data structures for this problem. Implement a method dispatchCaL L () which assigns a call to the first available employee
struct Call {
string phoneNumber;
string content;
};
enum RANK {
RESPONDENT, MANAGER, DIRECTOR
};
class Employee {
public:
Employee(int level) : level(level) {}
int getLevel() const { return level; }
bool isFree() const { return calls.empty(); }
virtual bool handleCall(Call call) = ;
protected:
queue<Call> calls;
private:
int level;
};
class Respondent : public Employee {
public:
Respondent() : Employee(RANK::RESPONDENT) {}
bool handleCall(Call call) { /*...*/ return true;}
};
class Manager: public Employee {
public:
Manager() : Employee(RANK::MANAGER) {}
bool handleCall(Call call) { /*...*/ return true;}
};
class Director : public Employee {
public:
Director(): Employee(RANK::DIRECTOR) {}
bool handleCall(Call call) {/*...*/ return true; }
};
class CallCenter {
public:
bool dispatchCall(Call call) {
for (map<int, vector<Employee> >::iterator it = employees.begin();
it != employees.end(); it++) {
for (int i = ; i < it->second.size(); ++i) {
if (it->second[i].isFree() && it->second[i].handleCall(call)) {
return true;
}
}
}
return false;
}
void addEmployee(Employee &employee) {
employees[employee.getLevel()].push_back(employee);
}
private:
map<int, vector<Employee> > employees;
};
Careercup | Chapter 8的更多相关文章
- Careercup | Chapter 1
1.1 Implement an algorithm to determine if a string has all unique characters. What if you cannot us ...
- Careercup | Chapter 3
3.1 Describe how you could use a single array to implement three stacks. Flexible Divisions的方案,当某个栈满 ...
- Careercup | Chapter 2
链表的题里面,快慢指针.双指针用得很多. 2.1 Write code to remove duplicates from an unsorted linked list.FOLLOW UPHow w ...
- Careercup | Chapter 7
7.4 Write methods to implement the multiply, subtract, and divide operations for integers. Use only ...
- CareerCup Chapter 9 Sorting and Searching
9.1 You are given two sorted arrays, A and B, and A has a large enough buffer at the end to hold B. ...
- CareerCup chapter 1 Arrays and Strings
1.Implement an algorithm to determine if a string has all unique characters What if you can not use ...
- CareerCup Chapter 4 Trees and Graphs
struct TreeNode{ int val; TreeNode* left; TreeNode* right; TreeNode(int val):val(val),left(NULL),rig ...
- Careercup | Chapter 6
6.2 There is an 8x8 chess board in which two diagonally opposite corners have been cut off. You are ...
- Careercup | Chapter 5
5.1 You are given two 32-bit numbers, N andM, and two bit positions, i and j. Write a method to inse ...
随机推荐
- POJ 1159 回文串-LCS
题目链接:http://poj.org/problem?id=1159 题意:给定一个长度为N的字符串.问你最少要添加多少个字符才能使它变成回文串. 思路:最少要添加的字符个数=原串长度-原串最长回文 ...
- jquery的siblings()
jquery 点击 感兴趣 感兴趣变为 蓝色 去掉onclick事件 不感兴趣 变为 黑色 加上点击事件 点击 不感兴趣 不感兴趣变为 蓝色 去掉onclick 感兴趣 变为 黑色 加上点击事件 ht ...
- 【转】详解C#中的反射
原帖链接点这里:详解C#中的反射 反射(Reflection) 2008年01月02日 星期三 11:21 两个现实中的例子: 1.B超:大家体检的时候大概都做过B超吧,B超可以透过肚皮探测到你内 ...
- MFC 动态修改对话框标题
在对应对话框的初始化函数OnInitDialog()中添加以下代码: CString title; title.Format("%d",Id);//在标题栏动态显示Id的值 thi ...
- ZOJ3229 Shoot the Bullet(有源汇流量有上下界网络的最大流)
题目大概说在n天里给m个女孩拍照,每个女孩至少要拍Gi张照片,每一天最多拍Dk张相片且都有Ck个拍照目标,每一个目标拍照的张数要在[Lki, Rki]范围内,问最多能拍几张照片. 源点-天-女孩-汇点 ...
- 关于dialog置于底层的问题
我今天开发的一个dialog,引用代码中已有的,发现是居中的 接下来,我要把它置为底部 然后,我的思路就是从dialog的view设置入手,还用了setgravity,最后还是不成功 所以,后来,我休 ...
- Leetcode Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...
- 10秒钟sublime text 3安装SVN插件
注意:此处我提前已经安装了towerSVN,你可能需要提前安装好 towerSVN,之前安装redis之后我才明白,安装插件时安装软件好像 是一个必要的步骤,也就是说安装插件只是让你能在这里使用你已 ...
- TCP/IP基础知识
TCP/IP基础知识 网络 TCP/IP 引言 本篇属于TCP/IP协议的基础知识,重点介绍了TCP/IP协议簇的内容.作用以及TCP.UDP.IP三种常见网络协议相关的基础知识. 内容 TCP/IP ...
- Idea_Intellij Idea 12 生成serialVersionUID的方法
默认情况下Intellij IDEA是关闭了继承了java.io.Serializable的类生成serialVersionUID的警告.如果需要ide提示生成serialVersionUID,那么需 ...