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 ...
随机推荐
- Zepto tap 穿透bug
当两个层重叠在一起时,使用Zepto的tap事件时,点击上面的一层时会触发下面一层的事件,特别是底层如果是input框时,必“穿透”,“google”说原因是“tap事件实际上是在冒泡到body上时才 ...
- jQuery-品牌列表案例
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- [POJ1015]Jury Compromise
题目大意:要求你从n个人中选出m个,每个人有两个值p[i],D[i],要求选出的人p总和与D总和的差值最小.若有相同解,则输出p总+D总最大的方案. 动态规划. 一直在想到底是n枚举外面还是m放外面, ...
- 安装和配置Tomcat
今天第一个技术难题,说难也不难,被鄙视的彻彻底底. 理解上的问题纠正:Xftp里面我们看到的只是自己电脑上和所连接服务器里面的文件,集群里面有master 服务器和slaves 服务器 ,一个Nam ...
- HDU4307 Matrix(最小割)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=4307 Description Let A be a 1*N matrix, and each ...
- Codeforces 653D Delivery Bears(最大流)
题目大概说有一张n个点m条边的简单有向图,每条边只能允许一定总量的货物通过.要让x只熊从1点到n点运送货物,每只熊都要运送且运送的货物重量都一样,求该重量的最大值. 二分重量判断是否成立. 如果已知重 ...
- ural 2071. Juice Cocktails
2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...
- checkbox属性checked="checked"通过js已设置,但是不勾选
1.通过 attr('checked','checked') 来设置checkbox时,重复点击,虽然checked属性设置正确,但是checkbox没有被勾选 ,如下代码:(代码是全选功能) $(' ...
- ACM: HDU 1028 Ignatius and the Princess III-DP
HDU 1028 Ignatius and the Princess III Time Limit:1000MS Memory Limit:32768KB 64bit IO Form ...
- CDOJ 1437 谭松松的旅游计划 Label:倍增LCA && 最短路
谭松松的旅游计划 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit ...