c********2 发帖数: 56 | 1 面的是Associate C++ Developer,下面是面试题,光顾着记题了,最后只有56%的通过
率,要到
80%才能ONSITE,算是帮大家做点贡献吧,他家在招人,赶快去投简历
1) #include
using namespace std;
struct A{
A(int value) : m_value(value){}
int m_value;
};
struct B:A {
B(int value):A(value){}
};
int main(){
try {
try{
throw B(5);
}
catch(A a){
a.m_value *=2;
throw;
}
catch(B b){
b.m_value -=2;
throw b;
}
}
catch(A a){
... 阅读全帖 |
|
g*****1 发帖数: 998 | 2 【 以下文字转载自 Programming 讨论区 】
发信人: guagua1 (), 信区: Programming
标 题: 请教2道c++的题
发信站: BBS 未名空间站 (Tue Jan 10 19:21:47 2012, 美东)
class base{};
class derived{};
class derived2: public base, derived {};
which is true?
1) This is illegal
2) derived2 is derived public from base and private from derived
3) derived2 is derived public from base and public from derived
4) derived2 is derived public from base and protected from derived
class X{
public:
X& operator=(const X& rhs);
const X& operator+(con... 阅读全帖 |
|
s*w 发帖数: 729 | 3 不知道为啥,我的 heap 时灵时不灵的?请看下面的 code 和输出显示
#include
#include
#include
using namespace std;
struct ListNode {
int val;
ListNode *next;
ListNode(int v):val(v),next(NULL) {}
};
bool minHeapPredicate(ListNode* lhs,ListNode* rhs) {
return lhs->val > rhs->val;
}
class Solution {
public:
ListNode *mergeKLists(vector lists) {
ListNode *retHead = NULL, *retTail = NULL;
// store values and nodes into heap
vector ... 阅读全帖 |
|
f**********t 发帖数: 1001 | 4 多谢!现在fixed. :)
inline bool operator!=(const X& lhs, const X& rhs){return !(lhs == rhs);}
看来在!=里面,左右两边的值都得是cost才行。 |
|
b**i 发帖数: 2 | 5 楼上说的对,用make_heap, pop_heap, push_heap 来做。
vector heap;
heap.push_back(1);
heap.push_back(2);
make_heap(heap.begin(), heap.end()); // 这样就把heap变成了一个max heap
auto cmp = [](int lhs, int rhs){return lhs > rhs;};
make_heap(heap.begin(), heap.end()); // 把heap变成了 min heap
下面都用minheap举例子,如果是maxheap不需要传第三个参数。
pop_heap(heap.begin(), heap.end(), cmp); // 现在 heap.back() 是heap的最上面
的那个元素,已经pop出来了
heap.push_back(998);
push_heap(heap.begin(), heap.end(), cmp); // 这样就把998正确插入到minheap了
heap的top应该可以通过front() 来... 阅读全帖 |
|
L******k 发帖数: 395 | 6 Problem Description
-------------------
Your task is to write a command-line program to evaluate a set of
equations, each specified on separate lines. An equation is defined
by:
=
is the left-hand side of the equation and is always a variable
name. A variable name can only be composed of letters from the
alphabet (e.g. for which isalpha(c) is 1). is the right hand
side of the equation and can be composed of variables, unsigned
integers, and the + operator.
Here is one exa... 阅读全帖 |
|
w******t 发帖数: 16937 | 7 分特,想看专业的?
看这个。声明:因为网络安全原因,我删去了一些必须删去的内容。
http://schema.org/WebPage">Google
|
|