由买买提看人间百态

topics

全部话题 - 话题: endl
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
m**o
发帖数: 5261
1
来自主题: Programming版 - c++ print endl
I am not very familiar with c++. I want to print out an integer matrix line
by line. Why the cout< void Matrix::printMatrix(){
for(unsigned int i=0; i {
Matrix::printRow(i);
}
}
void Matrix::printRow(unsigned int rownumber)
{
matrix_row_t row=grid.at(rownumber);
for(unsigned int i=0; i < row.size(); i++)
{
cout< }
cout< }
S**I
发帖数: 15689
2
☆─────────────────────────────────────☆
careerchange (Stupid) 于 (Sat Jun 4 20:25:58 2011, 美东) 提到:
void reversePrint(Node* head) {
if(head=NULL) {
cout << "Empty List. No node to print." << endl;
return;
}
if(head->next=NULL) {
cout << head->data << endl;
return;
} else {
Node* temp=head;
head=temp->next;
reversePrint(head);
cout << temp->data << endl;
return;
}
}
☆─────────────────────────────────────☆
speeddy (Wade) 于 (Sat Jun 4 20:30:33 ... 阅读全帖
v******y
发帖数: 84
3
来自主题: Programming版 - 前几天有人问rvalue reference的
这是我的理解,不对的请指出,谢谢
The usage of rvalue reference &&
Define a class
class MyClass{
public:
MyClass(){/*require for const MyClass cMyClass init. Without this default
constructor, const MyClass will have to be declared and defined as such:
const MyClass cMyClass=MyClass(). MyClass() here will call synthesized
constructor automatically generated by compiler. This synthesized
constructor can not directly initiate const. So following is illegal without
default constructor: const MyClass cMyClass;*/}
};... 阅读全帖
p****e
发帖数: 37
4
来自主题: JobHunting版 - 两道F电面题
贴个楼主事后写的:
bool _re_match(const char *str, const char *pattern, char prev_char) {
// 如果str匹配完,检查pattern是否匹配完,或者还剩一个"*"
if (*str == NULL)
return (*pattern == NULL || (*pattern == '*' && *(pattern+1) == NULL
)) ? true : false;
if (*pattern != '*')
{
// 如果当前pattern char不是'*', 试图匹配当前的str char, 然后
继续。
if (*pattern == '.' || *pattern == *str)
{
if (_re_match(str+1, pattern+1, *pattern))
return true;
... 阅读全帖
p****e
发帖数: 37
5
来自主题: JobHunting版 - 两道F电面题
贴个楼主事后写的:
bool _re_match(const char *str, const char *pattern, char prev_char) {
// 如果str匹配完,检查pattern是否匹配完,或者还剩一个"*"
if (*str == NULL)
return (*pattern == NULL || (*pattern == '*' && *(pattern+1) == NULL
)) ? true : false;
if (*pattern != '*')
{
// 如果当前pattern char不是'*', 试图匹配当前的str char, 然后
继续。
if (*pattern == '.' || *pattern == *str)
{
if (_re_match(str+1, pattern+1, *pattern))
return true;
... 阅读全帖
s****n
发帖数: 700
6
来自主题: Programming版 - a question about bitwise operation
那看看这个code
#include
using namespace std;
int main() {
int i;
unsigned int ui;
long l;
unsigned long ul;
long long ll;
unsigned long long ull;
i = 1 << (sizeof(i) * 8 - 1);
cout << "sizeof(i) is " << sizeof(i) << endl;
cout << "i is " << i < ui = 1 << (sizeof(ui) * 8 - 1);
cout << "sizeof(ui) is " << sizeof(ui) << endl;
cout << "ui is " << ui < l = 1 << (sizeof(l) * 8 - 1);
cout << "sizeof(l) is " << sizeof(l) << endl;
cout << "l is " << l < ul = 1 << (sizeof(ul) * 8 -... 阅读全帖
J**********y
发帖数: 1891
7
#include "stdafx.h"
#include
#include
using namespace std;
class Base
{
public:
Base(){ cout << "Base-ctor"< ~Base(){cout << "Base-dtor"< virtual void f(int) {cout << "Base::f(int)"< virtual void f(double) {cout << "Base::f(double)"< virtual void g(int i=10) {cout << "Base::g()"< void g2(int i=10) {cout << "Base::g2()" << i< };
class Derived : public Base
{
public:
Derived() {cout << "Derived-ctor... 阅读全帖
s*w
发帖数: 729
8
just practicing c++11 multi-threading and got the following code to try out
your example
problem with my code now:
1. it does not deal with last line of input file
2. it has deadlock for certain test file
Anyone familiar with c++11 multi-threading?
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const int MAXCAPACITY = 3;
mutex mx;
deque data;
map阅读全帖
s*w
发帖数: 729
9
发信人: yangguo1220 (yangguo), 信区: JobHunting
标 题: 一道count frequency of all words的面试题
发信站: BBS 未名空间站 (Wed Sep 18 20:44:44 2013, 美东)
100G的文本文件,4G内存,4个CPU。写一个程序:列出所有文本文件中的word
frequency,并output到一个最终文件中, 格式为 . 这个最终文件
的size也可能比内存小.
大家有啥建议?
【 以下文字转载自 JobHunting 讨论区 】
发信人: saw (句子熊), 信区: JobHunting
标 题: Re: 一道count frequency of all words的面试题
发信站: BBS 未名空间站 (Thu Sep 19 02:18:15 2013, 美东)
just practicing c++11 multi-threading and got the following code to try out
your example
problem wi... 阅读全帖
e********r
发帖数: 2352
10
来自主题: JobHunting版 - Epic Written Interview
在本地的考试中心预约的上机考试。考试有三个部分,1.数学题,2.给出一种新的编程
语言的语法,回答相应问题,3. Programming Test 要求速度和准确性both important
Programming test 答得不好,肯定不行了,把面试题发上来让大家做做。做了3个半小
时,快累死了。
数学题基本上就是脑筋急转弯,举几个例子
1. You have three kinds of magazines, all but two are Times, all but two are
Science, all but two are Nature. How many magazines in total do you have?
3 books
2. Only one of the answers is true
A. All of the below are true
B. All answers are true
C. One of the above is true
D. All of the above are true
E. None of the above ar... 阅读全帖
e*****w
发帖数: 144
11
加减乘,没用+-*/号。
#include
using namespace std;
int Add(int a, int b) {
return (b ? Add(a ^ b, (a & b) << 1) : a);
}
int Sub(int a, int b) {
return Add(a, Add(~b, 1));
}
int Mul(int a, int b) {
if (b == 0) return 0;
if (b < 0) return Mul(Sub(0, a), Sub(0, b));
return Add(a, Mul(a, Sub(b, 1)));
}
int main() {
cout << "Add(3, 4) = " << Add(3, 4) << endl;
cout << "Add(3, -8) = " << Add(3, -8) << endl;
cout << "Add(-8, 40) = " << Add(-8, 40) << endl;
cout << "Sub(3, 4) = " <<... 阅读全帖
e*****w
发帖数: 144
12
加减乘,没用+-*/号。
#include
using namespace std;
int Add(int a, int b) {
return (b ? Add(a ^ b, (a & b) << 1) : a);
}
int Sub(int a, int b) {
return Add(a, Add(~b, 1));
}
int Mul(int a, int b) {
if (b == 0) return 0;
if (b < 0) return Mul(Sub(0, a), Sub(0, b));
return Add(a, Mul(a, Sub(b, 1)));
}
int main() {
cout << "Add(3, 4) = " << Add(3, 4) << endl;
cout << "Add(3, -8) = " << Add(3, -8) << endl;
cout << "Add(-8, 40) = " << Add(-8, 40) << endl;
cout << "Sub(3, 4) = " <<... 阅读全帖
w*******r
发帖数: 2953
13
来自主题: JobHunting版 - 一道OO设计题
改完的程序在下面,这下疾病可以随便定义了,也可以治病了。
想给给个病安个计数器,记得好像有个什么关健词可以让所有的object改动的都是
同一个变量而不是各自的变量(counter),记不起来了,所以这个counter打印得
不对,有知道的告诉我一声。
#include
#include
#include
using namespace std;
class Disability
{
public:
Disability(){counter = 0; };
Disability(string, string);
~Disability(){};
string get_disease_name() const { return name; };
string get_disease_desc() const { return desc; };
void incr_sick_human_counter() {counter++; };
unsigned long get_hum... 阅读全帖
w*******s
发帖数: 96
14
再来一个拍拍:
////////////////////////////////////////////////////////////////////////////
////////
// Problem 1.1:
// Analysis and points:
// 1. strig operation(scan)
// 2. How to determine whether it's duplicate string?
// Method 1: using one hashtable, if it's already in
hashtable,
// it's duplicate, otherwise add into hashtable.
Complexity O(n)
// Method 2: for each characer, check whether it's duplicated
// ... 阅读全帖
f*******t
发帖数: 7549
15
来自主题: JobHunting版 - 2道算法题。 求教大家!
找出了一年多前写的逆波兰处理算数表达式的代码,强烈建议有兴趣的自己实现一下:
#include
#include
#include
#include
#define BUFFSIZE 1024
using namespace std;
struct Token {
bool isNum;
int num;
char op;
Token();
Token(const Token& t);
};
Token::Token()
{
isNum = false;
num = 0;
op = 0;
}
Token::Token(const Token& t)
{
isNum = t.isNum;
num = t.num;
op = t.op;
}
Token *getToken(const char expr[], int& idx)
{
Token *res = NULL;
while(expr[idx] == ' ')
... 阅读全帖
a******e
发帖数: 124
16
来自主题: JobHunting版 - 请教一下怎么写unit test
以前写程序test时候只是在main函数里简单输出一下看看对不对,最近想学一下unit
test,这个有什么格式要求吗(我看有些人用assert())?比如用c++语言想写一个
binary search的unit test该如何写,谢谢!
试着写了一个,不知道这样算不算unit test
#include
using namespace std;
int BinarySearch(int arr[], int size, int target){
int high=size-1;
int low=0;
int mid;
while(low<=high){
mid=low+(high-low)/2;
if(arr[mid]==target){
return mid;
}
else if(arr[mid]>target){
high=mid-1;
}
else{
low... 阅读全帖
z****e
发帖数: 2024
17
来自主题: Programming版 - 大家来做题C++。
#include
using namespace std;
class blah{
public:
blah(int i):_i(i){
cout<<"blah()"< }
~blah(){
cout<<"~blah("<<_i<<")"< }
int get(){
cout<<_i< }
private:
int _i;
};
class base{
public:
base():ob(3){
i=0;
cout<<"base()"< }
void out(){
cout<<"base.out()"< }
void f(){
cout<<"base.f()"< cout<<"i= "< cout<<"ob.get()= "< }
~base(){
cout<<"~base()"< }
vo
g*********s
发帖数: 1782
18
来自主题: Programming版 - protected/private inheritance
Just did a quick test. So what's the diff b/w private inheritance and
protected inheritance here?
#include
using namespace std;
class B {
public:
void f() { cout << "B::f()\n"; }
virtual void g() { cout << "B::g()\n"; }
int B_public;
protected:
int B_protected;
private:
int B_private;
};
class D_pub: public B {
public:
void f() { cout << "D_pub::f()\n"; }
virtual void g() { cout << "D_pub::g()\n"; }
void h() { cout << B_protected << endl; }
//void j... 阅读全帖
J**********y
发帖数: 1891
19
class A
{
public:
int a;
};
class B
{
public:
int a;
B(int aa=0)
{
a=aa;
}
~B(){};
};
class C: public A, public B
{
//public:
// C(int cc):B(cc)
// {
// };
};
int _tmain(int argc, _TCHAR* argv[])
{
char aa[100]="0123456789";
cout << sizeof(func()) << endl;
cout << sizeof(int) << endl;
cout << sizeof(A) << endl;
cout << sizeof(B) << endl;
cout << sizeof(C) << endl;
A a;
B b;
C c;
cout << a.a << endl;
cout << b.a ... 阅读全帖
h**********c
发帖数: 4120
20
来自主题: Computation版 - 继续我们计算non-prime number 的探险
先前提到过 y = sin(a * pi /x), 对于质数a 在(1,a)是没有解得。
写了段程序,用牛顿法算 x, 跑了跑发现,原来这个一维系统有很多folds,又想了想
能不能用二维的系统来解这个问题呢?于是又了如下的构造
f = (f1,f2)^t
f1(x1,x2) = (x1 + exp(x2))* sin(pi * a /x1);
f2(x1,x2) = (x1*x1 -x2*x2)
求 f --〉0
这个系统看起来有个不错的jacobian,跑了跑程序,居然收敛了,但不知道收敛到哪里
去了,您有时间帮忙看看吧,能不能有更好的构造。或者用什么论证着干脆就是不可行
的,免得骑自行车去月球。
附程序c++
#include
#include
using namespace std;
#define PI (atan(1.0)*4.0)
#define __VERYSMALL (1.0E-10)
#define __ITERATIONLIMIT 20
bool isVerySmall (double d) {
return (a... 阅读全帖
h**********c
发帖数: 4120
21
来自主题: Mathematics版 - 继续我们计算non-prime number 的探险
先前提到过 y = sin(a * pi /x), 对于质数a 在(1,a)是没有解得。
写了段程序,用牛顿法算 x, 跑了跑发现,原来这个一维系统有很多folds,又想了想
能不能用二维的系统来解这个问题呢?于是又了如下的构造
f = (f1,f2)^t
f1(x1,x2) = (x1 + exp(x2))* sin(pi * a /x1);
f2(x1,x2) = (x1*x1 -x2*x2)
求 f --〉0
这个系统看起来有个不错的jacobian,跑了跑程序,居然收敛了,但不知道收敛到哪里
去了,您有时间帮忙看看吧,能不能有更好的构造。或者用什么论证着干脆就是不可行
的,免得骑自行车去月球。
附程序c++
#include
#include
using namespace std;
#define PI (atan(1.0)*4.0)
#define __VERYSMALL (1.0E-10)
#define __ITERATIONLIMIT 20
bool isVerySmall (double d) {
return (a... 阅读全帖
l*********y
发帖数: 142
22
来自主题: JobHunting版 - 攒人品之facebook电面面经
#include
#include
#include
#include
#include
#include
#include
using namespace std;
class Counter {
public :
Counter() {
counter = 0;
}
void increment() {
counter++;
}
void decrement() {
counter --;
}
int getValue() {
return counter;
}
private:
int counter;
};
class COWString {
public:
COWString() {
pointer = NULL;
rc = new Counter();
}... 阅读全帖
C***U
发帖数: 2406
23
#include
#include
#include
#define MAX 10000
int main(int argc, char *argv[]){
std::vector numbers1;
std::vector numbers2;
int k = atoi(argv[3]);
if(argc < 4)
std::cout << "we need 2 files and a number." << std::endl;
std::cout << "we need find " << k << "th number" << std::endl;
std::cout << "reading first array of numbers ..." << std::endl;
std::ifstream f1(argv[1]);
if(!f1){
std::cout << "cannot open... 阅读全帖
v******9
发帖数: 1
24
来自主题: JobHunting版 - 请教一个OOP的C++问题
可以不需要typeid,不过就比较奇怪一点。
tester.h
================
class A{
public:
virtual void invoke();
};
class B:public A{
public:
void virtual invoke();
};
class C:public A{
public:
void invoke();
};
class D:public A{
public:
void invoke();
};
=====================
main.cpp
=====================
#include
#include
#include "tester.h"
using namespace std;
void test(A* a){
cout<<"test: A "< };
void test(B* a){
cout<<"test: B "< };
void test(C* a){
co... 阅读全帖
y******g
发帖数: 4
25
来自主题: JobHunting版 - 这道狗家的题有什么好的思路吗?
#include
#include
#include
#include
using namespace std;
struct Item {
int counter;
char c;

Item(): counter(0), c('\0') {};
Item(int counter_, char c_) : counter(counter_), c(c_) {};
Item(const Item &anotherItem): counter(anotherItem.counter), c(
anotherItem.c) {};
};
struct ItemCompare {
Item* prev;

ItemCompare(Item* prevItem): prev(prevItem) {};

bool operator() (const Item &item1, const Item &item2) {
... 阅读全帖
t******1
发帖数: 152
26
using namespace std;
#include
#include
int main(){
int *a,*b; //没有初始化的指针a和b
cout<<&a<<" "<<&b< //分别为0x28ff3c和0x288ff38。注意二者之差为4,
//所以此环境为32位,即4Bytes
cout< //是什么
//假设为0x100000和0x200000。
cout<<*a<<" "<<*b< ... 阅读全帖
m*********a
发帖数: 3299
27
const char i='x';
const char *cp=&i;
char *p;
p=const_cast(cp);
std::cout<<&i<<" "< address
*p='y';
std::cout<<*p< std::cout<<*cp< std::cout< 同样的
char i='x';
const char *cp=&i;
char *p;
p=const_cast(cp);
std::cout<<&i<<" "<阅读全帖
w****g
发帖数: 206
28
来自主题: JobHunting版 - 弱问个C++ 问题 (const_cast)
运行一下 程序:
int main() {
const int i = 0;
int * j;
cout << "&j=" << &j << endl;
cout << "&i=" << &i << endl;
cout << "j=" << j << endl;
j = const_cast(&i);
*j = 2;
cout << "i=" << i << endl;
cout << "*j=" << *j << endl;
cout << "j=" << j << endl;
cout << "&i=" <<&i < }
得到结果:
&j=0xbf93a658
&i=0xbf93a65c
j=0
i=0
*j=2
j=0xbf93a65c
&i=0xbf93a65c
这就是说:j 和&i是一样的,但是为什么i和*j不一样呢?
Y********f
发帖数: 410
29
来自主题: JobHunting版 - heap里面delete一个非root的节点
测试过的代码:
#include
#include
using namespace std;
void deleteNode(int heap[], int n, int pos)
{
// put the last elements to where the node removed
heap[pos] = heap[n-1];
// adjust elements above pos
int i = pos;
while(i != 0 && heap[i] < heap[(i - 1) / 2])
{
swap(heap[i], heap[(i - 1) / 2]);
i = (i - 1) / 2;
}
// adjust elements below pos
i = pos;
while(true)
{
if (2 * i + 1 > n -2)
{
//al... 阅读全帖
j*******g
发帖数: 4
30
来自主题: JobHunting版 - atoi很不好写,头都大了...
见过很多次这个题目了,一直没有招,下面写了一个又臭又长的, 方法很笨, 求建议
, 欢迎批评和指正
这样的代码面试可以通过吗?
////////////////////////////////////////////////////////////////
#include
#include
using namespace std;
//假设16位的整型
// -32768 , +32767
const char MAX_INT[] = "32767";
const char MIN_INT[] = "32768";
const int MAX_STRLEN = 5;
bool my_atoi(const char *str, int &res)
{
if(str == NULL)
{
cout << "Invalid pointer" << endl;
return false;
}

int index = 0;

if(str[index] == '-' || s... 阅读全帖
j*******g
发帖数: 4
31
来自主题: JobHunting版 - 弱弱的问一个问题
见过很多次这个题目了,一直没有招,下面写了一个又臭又长的, 方法很笨, 求建议
, 欢迎批评和指正
这样的代码面试可以通过吗?
////////////////////////////////////////////////////////////////
#include
#include
using namespace std;
//假设16位的整型
// -32768 , +32767
const char MAX_INT[] = "32767";
const char MIN_INT[] = "32768";
const int MAX_STRLEN = 5;
bool my_atoi(const char *str, int &res)
{
if(str == NULL)
{
cout << "Invalid pointer" << endl;
return false;
}

int index = 0;

if(str[index] == '-' ||... 阅读全帖
z**********8
发帖数: 229
32
来自主题: JobHunting版 - 汉若塔问题
#include
using namespace std;
#include
#include
class Tower{
private:
int index;//indicate the number of tower
stack one_tower;
public:
Tower(int i=0):index(i){}//constructor
int getindex();
void add(int d);
void moveTopTo(Tower t);
void print();
void moveDisks(int n,Tower Destination,Tower buffer);
};
int Tower::getindex()
{
return index;
}
void Tower::add(int d)
{
if((!one_tower.empty())&&(d>one_tower.top()))
cout<<"... 阅读全帖
d****n
发帖数: 1637
33
来自主题: JobHunting版 - heap&stack Linux vs. Windows  (转载)
//in windows
#include
#include
using namespace std;
class A{
public :
int a;
int b;
};
int main()
{
cout<<&main<

int before=4;
cout<<"STACK &before="<<&before< A objA;
void *p=malloc(1000);
cout<<"HEAP *p="< cout<<"&objA.a"<<&(objA.a)< cout<<"&objA.b"<<&(objA.b)< cout<<"objA="<<&objA< int after=4;
cout<<"STACK &after="<<&after< return 0;
}
//output from windows wi... 阅读全帖
d****o
发帖数: 2
34
来自主题: JobHunting版 - 面试F家让先做programming puzzle
抛砖引玉
#include
#include
#include
const int kMaxK = 5;
const int kMaxN = 8;
const int kMaxS = 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5;
#define DEBUG(v) std::cerr << #v << " = " << (v) << "\n"
int N, K, max_state;
short top[kMaxS][kMaxK];
int G[kMaxS][kMaxK * (kMaxK - 1) + 1];
int src = 0, dst = 0;
int f[kMaxS];
int pow(int base, int power) {
int r = 1;
for (int i = 0; i < power; r *= base, ++i);
return r;
}
int get(int num, int d) {
for (int i = 0; i < d; num /= K, ++i)... 阅读全帖
d****o
发帖数: 2
35
来自主题: JobHunting版 - 面试F家让先做programming puzzle
抛砖引玉
#include
#include
#include
const int kMaxK = 5;
const int kMaxN = 8;
const int kMaxS = 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5;
#define DEBUG(v) std::cerr << #v << " = " << (v) << "\n"
int N, K, max_state;
short top[kMaxS][kMaxK];
int G[kMaxS][kMaxK * (kMaxK - 1) + 1];
int src = 0, dst = 0;
int f[kMaxS];
int pow(int base, int power) {
int r = 1;
for (int i = 0; i < power; r *= base, ++i);
return r;
}
int get(int num, int d) {
for (int i = 0; i < d; num /= K, ++i)... 阅读全帖
b****f
发帖数: 138
36
前面的评论没看,i不回溯的确过不了,这个暴力法都可以过,但貌似超时了,感觉现
在只能用KMP了
class Solution {
public:
bool isMultiple (string s){
int N=s.size();
if(N<3) return false;
int len=1;
int start=0;
for(int i=1;i if(s[start]==s[i]){
start++;
if(start>=len) start=0;
}
else{
len++;
i=len-1;
start=0;
}
if(len>N/2) return false;
... 阅读全帖
b****f
发帖数: 138
37
前面的评论没看,i不回溯的确过不了,这个暴力法都可以过,但貌似超时了,感觉现
在只能用KMP了
class Solution {
public:
bool isMultiple (string s){
int N=s.size();
if(N<3) return false;
int len=1;
int start=0;
for(int i=1;i if(s[start]==s[i]){
start++;
if(start>=len) start=0;
}
else{
len++;
i=len-1;
start=0;
}
if(len>N/2) return false;
... 阅读全帖
y*****i
发帖数: 141
38
来自主题: JobHunting版 - 问道G家的题
照着Maxthon的编码解法写了一个:
#include
#include
#include
#include
using namespace std;
bool bool_vec_none(const vector & vec) {
for(auto elem : vec) {
if (elem) {
return false;
}
}
return true;
}
bool bool_vec_all(const vector & vec) {
for(auto elem : vec) {
if (!elem) {
return false;
}
}
return true;
}
string word_abbreviation(string target, vector dict)
{
if (t... 阅读全帖
b******i
发帖数: 914
39
来自主题: JobHunting版 - 问一道Facebook近期电面题
大体思路就是记录下所有当前是反括号但是没有正括号pop出来的,和最后剩下的正括号
class Solution {
public:
string balance(string s) {
int n = s.length();
if(n == 0)
return 0;
vector stk;
vector to_remove(n, false);
for(int i = 0; i < n; i++) {
char c = s[i];
if(c == '(') {
stk.push_back(i);
} else {
if(stk.empty())
to_remove[i] = true;
else {
stk.p... 阅读全帖
r*******y
发帖数: 1081
40
来自主题: Programming版 - question about c++ constructor
The code below is OK
//4.cpp
#include
using namespace std;
class M{
int i;
public:
M(){cout << "default constructor" << endl;}
M(int ii):i(ii){cout << "constructor"<< endl;}
M(const M & mm):i(mm.i){cout << "copy constructor"< };
int main(){
M mm = 1;
}
If I run the program, output is
constructor
But If I changed the copy constructor as
M(M & mm):i(mm.i){cout << "copy constructor"< that is, the parameter is M & instead of const M&
N... 阅读全帖
d*******l
发帖数: 338
41
来自主题: JobHunting版 - 尘埃落定里面的矩形题
不是很麻烦吧。
#include
#include
#include
using namespace std;
#define MP make_pair
typedef pair PII;
typedef vector VI;
struct FindVertex
{
struct rect
{
int x1, y1, x2, y2;
rect(int a, int b, int c, int d) : x1(a), y1(b), x2(c), y2(d) {}
};
vector rects;
void add(int a, int b, int c, int d)
{
rect r(a, b, c, d);
rects.push_back(r);
}
void solve()
{
int i, j;
VI v;
... 阅读全帖
S**I
发帖数: 15689
42
来自主题: JobHunting版 - C++ Q83: 这个const_cast什么意思?
I bet if you run a debugger for this example, you will see that both a and *
b have value 3 after "*b = 3", but the output of "std::cout << a" is still 2.
The reason is when compiler sees "std::cout << a", since a is declared as
const and initialized to 2, it may replace this statement with "std::cout <<
2". The compiler never bothers to check whether the value of a has been
modified before "std::cout << a". This is a valid optimization and many
compilers do it.
Change you code to the following ... 阅读全帖
L**********u
发帖数: 194
43
来自主题: JobHunting版 - Exposed上一道string permutation的题
This problem can be solved by binary representation of an integer.
I am a rookie of C++. thanks for comments
my codes
#include
#include
#include
using namespace std;
const int N=5;
void subset(int arr[], int n)
{
bitset n_bit(n);
cout<<"{";
for(int i=0;i if(n_bit[i]==1)
cout< cout<<"};";
cout< }
//main function
int main()
{
cout<<"The set has "< int arr[N];
for(int i=0;i arr[i]=... 阅读全帖
g*******s
发帖数: 2963
44
来自主题: JobHunting版 - 面完G的电面了,忐忑
这个行不?constructor里我pass了container(这里是vector),因为我不知道没有
container该怎么写hasNext()? 如果假设原始iterator已经有hasNext()和next()了,
那这俩函数应该不用改吧?看成black box就行了,直接在peek里引入个temp变量就行
了。
#include
#include
using namespace std;
template
class Wrapper {
public:
Wrapper(vector &v,
typename vector::iterator it)
:_vec(v),_it(it),_tempIt(it){
_it = _vec.begin();
};
bool hasNext(){
_tempIt = _it;
return (++_tempIt)!=_vec.end();
};
... 阅读全帖
w****x
发帖数: 2483
45
来自主题: JobHunting版 - 为什么大家那么喜欢做leetcode?

//Spirally print M*N array
const int M = 5;
const int N = 3;
void SpiralPrint2(int A[M][N])
{
int nX = 0;
int nY = 0;
int nLenth = N;
int nHeight = M;
//nothing to say, completely swapped the row and col ++ operation
while (nLenth > 0 && nHeight > 0)
{
//set tarting point
int nIterX = nX;
int nIterY = nY;
//when length or height is equal to 1, needs special care
if (nLenth == 1)
{
for (int i = 0; i < nHeight... 阅读全帖
o********n
发帖数: 193
46
来自主题: JobHunting版 - Binary search很靠基本功啊
test case:
#include
void BinarySearch_Test()
{
int A1[1] = {4};
int A2[2] = {4, 5};
int A3[8] = {2,4,6,6,6,6,6,9};
int A4[8] = {2,4,6,6,8,8,8,9};
cout << FindInsertionPoint(A1, 1, 1) << endl;
cout << FindInsertionPoint(A1, 1, 10) << endl;
cout << FindInsertionPoint(A2, 2, 1) << endl;
cout << FindInsertionPoint(A2, 2, 10) << endl;
for (int i = 0; i <= 10; i++)
cout << i << "=" << FindInsertionPoint(A3, 8, i) << " ";
cout << endl;
for ... 阅读全帖
d**e
发帖数: 6098
47
☆─────────────────────────────────────☆
oneid (Mobius) 于 (Fri Dec 28 19:12:49 2012, 美东) 提到:
比如careercup,glassdoor上每个公司那么多题,难道大家都做完了?
还是leetcode has OJ?比较容易发现code的问题?
但是大家觉得leetcode的题被问得几率比careercup上针对性的公司的题概率高么?不可
能把?
☆─────────────────────────────────────☆
luckynoob (菜鸟) 于 (Fri Dec 28 19:20:06 2012, 美东) 提到:
题目肯定是做不完的,重要的是实现一下一些重要方法吧,书还是要看的
☆─────────────────────────────────────☆
lolhaha (人生如棋,棋如人生) 于 (Fri Dec 28 19:21:35 2012, 美东) 提到:
careecup上的题你做得完吗?
那上面的很多回帖都有问题,没有正确答案

☆─────... 阅读全帖
c*******y
发帖数: 98
48
来自主题: JobHunting版 - 一道面试题,求解
DP好难,我来贴个无脑的,不知道题目理解对了没有。。
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int findMaxAllOneTopLeftSquare(vector>& matrix)
{
int i, j;
int m = matrix.size(); if (!m) return 0;
int n = matrix[0].size(); if (!n) return 0;
int max = min(m, n);

for (i=0; i for (j=0; j<=i; j++){
if (matri... 阅读全帖
b******i
发帖数: 914
49
来自主题: JobHunting版 - FB面试题一道 求解
贴个code,不过只test了几种case
/*
给一个list of string 和一个string s, 返回s是不是在list当中, s里可以包含一
个*代表一个任意字符。
*/
#include
#include
#include
using namespace std;
struct TrieNode {
TrieNode():is_word(false),children(26,nullptr) {}
bool is_word;
vector children;
};
class Solution {
public:
bool string_in_list(vector strings, string s) {
if(s.length() == 0 || strings.size() == 0)
return false;

// construct trie
... 阅读全帖
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)