由买买提看人间百态

topics

全部话题 - 话题: cout
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
K******g
发帖数: 1870
1
来自主题: JobHunting版 - 关于排列组合的总结
最后一种情况,我觉得没有这么复杂吧,比如说有array={a,b,c},如果是permutation
,那就是
getPermutation(char* array, int n)
{
if(n>=5)
{
cout< return;
}
int i;
for(i=0;i<3;i++)
{
permutation[n] = array[i];
getPermutaion(array, n+1);
}
}
如果是combination,那就是
getCombination(char* array,int n, int pos)
{
if(n>=5)
{
cout< return;
}
int i;
for(i=pos;i<3;i++)
{
combination[n] = array[i];
c********u
发帖数: 18
2
来自主题: JobHunting版 - 一道面试的选择题
c 么?
因为change destructor into virtual 可能影响derived class的一些使用
例如 :
class A
{
public:
A(){};
~A(){cout<<"destructor A"< };
class B: public A
{
public:
B(){};
virtual ~B(){cout<<"destructor B"< };
void main()
{
A* p=new B();
delete p;
}
This will result in:
destructor A;
But if we declare ~A() as virtual ~ A(), then the result will be:
destructor B;
destructor A;
所以,如果B的destructor析构了B的一些成员变量的话,在非virtual的情况下,这些
成员变量不会被析构掉,但是在virtual的情况下会。
i********s
发帖数: 133
3
来自主题: JobHunting版 - MS interview question
#include
int main(int argc, char **argv)
{
int num;
std::cout << "enter the size of the square:";
std::cin >> num;
std::cout << std::endl << "size =" << num << std::endl;

int (*array)[num] = new (int[num][num]);
int t = 0;
for(unsigned i=0; i for(unsigned j=0; j array[i][j] = ++t;
unsigned leftX = 0;
unsigned leftY = 0;
unsigned rightX = num;
unsigned rightY = num;
while(leftX <= rightX)
{
B*****t
发帖数: 335
4
my code for first problem, not tested.
const int N = 1000;
int b[N], a[N];
int n;
void dfs(int a[], int cur, int level) {
if(level==k) {
copy(b, b+k, ostream(cout," "));
cout< return;
}
int i, j;
for(i=cur+1; i<=n; i++) {
b[level+1] = a[i];
dfs(a, i, level+1);
}
}
z*******y
发帖数: 578
5
Void LevelTraversal(Node *root)
{
if(root == NULL) return;
queue q = new queue;
q.push(root);
q.push(NULL);
while(!q.empty() && q.size()!=1)
{
Node *temp = q.pop();
if(temp == NULL)
{
cout << endl;
q.push(NULL);
}
else
{
cout << temp->data << " ";
if(temp->left!=NULL)
q.push(temp->left);
if (temp->right!=NULL)
q.push(tem
b******n
发帖数: 823
6
来自主题: JobHunting版 - 1 11 21 1211 sequence的代码
写了个用string的
#include
#include
int main(int argc, char* argv[])
{
using namespace std;
cout << 1 << endl;
string s1, s2;
s1.push_back('1');
s1.push_back('1');
int loopcount = 0;
while(loopcount++ < 10)
{
cout << s1 << endl;
s1.push_back('a');
int i;
for (i=0; i {
int dupsize = 1;
while(s1[i] == s1[i+1])
{
dupsize++;
i++
b*******y
发帖数: 239
7
来自主题: JobHunting版 - 请教operator const char*() 的问题
原题也是在这个版上有人发的C++的其中一题,已copy下来:
class Person{
public:
Person(const char* szName);
const char* GetName() const;
/*put a function here*/
private:
char *m_szName;
};
int main()
{
Person person("John");
std::cout << Person;
return 0;
}
Referring to the sample code above, which one of the following member
functions do you add at the comment to support std::cout << person
statement?
A. std::string operator() { return GetName(); }
B. std::string ToString() { retur
f****4
发帖数: 1359
8
来自主题: JobHunting版 - 请教operator const char*() 的问题
conversion Operator :)
// code explains itself
class Test{
public:
operator const char*(){cout<<"Test"< };
void f(const char*)
{
cout<<"f()"< }
int main(){
Test t;
f(t);
return 0;
}
b********h
发帖数: 119
9
来自主题: JobHunting版 - C++ 程序求助
void las(vector v)
{
vector dp(v.size(), 1);
pair max(0, 1);
for(int i = 1; i < v.size(); ++i)
{
if(v[i] > v[i-1]) {
dp[i] = dp[i-1]+1;
if(dp[i] > max.second)
{
max.second = dp[i];
max.first = i;
}
}
else
dp[i] = 1;
}
for(int i = max.first-max.second+1; i <= max.first; ++i)
cout< cout< }
j**l
发帖数: 2911
10
假定K <= N
下面两种方法哪个更好?
方法一
int remain = N;
int select = K;
for (int i = 0; i < N; i++)
{
if (rand() % remain < select)
{
cout << i << " ";
--select;
}
--remain;
}
方法二,Knuth洗牌算法K步以后停止
for (int j = 0; j < K; j++)
{
int index = random(j, N-1); // including j and N-1
swap(array[j], array[index]);
cout << array[index] << " ";
}
p**********s
发帖数: 115
11
来自主题: JobHunting版 - 回馈本版,贴ms onsite面经
我来解typedef那题:
#include
using namespace std;
void staticFun(int num) {
cout << "static function" << endl;
}
class foo{
public:
void classFun(int num) {
cout << "function in a class" << endl;
}
};
typedef void (*myStaticFun) (int);
typedef void (foo::*myClassFun) (int);
int main()
{
myStaticFun testStaticFun = staticFun;
testStaticFun(6);
foo foo1;
myClassFun testClassFun = &foo::classFun;
(foo1.*testClassFun)(6);
return 0;
}
x*****m
发帖数: 29
12
来自主题: JobHunting版 - 好记(但不是最优)的combination算法
p.s. 看来之前那个题目说错话了, 就是觉得这个框架挺容易理解记忆的,既不是最优也不是最简单也不是最**最&&的,大
家轻拍..轻拍...
刚刚研究出来的~ 觉得还挺直观挺好记忆的~
Combination(s, start, k) : 从串s的位置start开始选k个元素
从位置1开始,分成选位置1和不选位置1的
然后递归调用,位置2,继续分成选位置2和不选位置2的...依次类推
如果剩下的和k相等,或者k==0了,就选择完毕了可以输出一个combination了
my code:
void Combination(std::string s, int start, int k) {
std::string temp;
int remaining = s.size() - start;

if (remaining == k) {
std::cout << s << std::endl;
return;
}
if (k == 0) {
std::cout << s.erase(start,
m******9
发帖数: 968
13
来自主题: JobHunting版 - 好记(但不是最优)的combination算法
我再贴个另外的写法吧,思路还是沿用你自己的思路,就是每个index 分成选择,或者
不选择。 你可以加上一个辅助数组,用来标记那些index被选择了,哪些没有被选择。
void combination(char* s, int start, bool* c, int n)
{
if(s[start]=='\0'){
print_combination(s, c, n);
return;
}
c[start] = true;
combination(s, start+1,c,n);
c[start] = false;
combination(s, start+1, c,n);
}
void print_combination(char* s, bool* c, int n)
{
for(int i=0; i if(c[i]==true)
cout< }
cout< }
s**9
发帖数: 207
14
来自主题: JobHunting版 - 这里聪明人多,来一道面试题
solution based on back tracking:
#include
using namespace std;
const int N=10;
const int M=10;
//sort a[N] first;
int a[N]={0,0, 2, 3, 4,5,5,8,9,10};
int level=0;
int order[N];
int sum=0;
void comb(int i){
order[level++]=a[i];
sum+=a[i];
if(sum>M){
for(int j=0;j cout< cout< }
if(level for(int j=i+1;j if(a[j]!=a[j-1])
comb(j);
}
}
sum-=a[i]
P*******b
发帖数: 1001
15
来自主题: JobHunting版 - C++ object size一问
class Grandpa {
public:
Grandpa() { cout << "Grandpa " << endl; }
virtual ~Grandpa() {}
};
class Ma : public virtual Grandpa {
public:
Ma() { cout << "Ma" << endl; }
virtual ~Ma() {}
virtual void print() {}
};
为啥这里Ma的object size 等于grandpa的object size?
P*******b
发帖数: 1001
16
来自主题: JobHunting版 - One C++ question
what problem does the following code have?
vector vec4;
vec4.reserve(10);
fill_n(vec4.begin(), 10, 1);
copy(vec4.begin(), vec4.end(), ostream_iterator(cout, " "));
cout << endl;
h***9
发帖数: 45
17
来自主题: JobHunting版 - One C++ question
//This seems to work
//The problem seems to be in vec4.reserve(10).
#include
#include
#include
#include
using namespace std;
int main(){
vector vec4 (10,0); // myvector: 10 10 10 10 10 10 10 10
// vec4.reserve(10);
fill_n(vec4.begin(), 10, 1);
copy(vec4.begin(), vec4.end(), ostream_iterator (cout, " "));
cout << endl;
return 0;
}
b********e
发帖数: 693
18
来自主题: JobHunting版 - one C++ question
what will happen if free an object in stack?
I did a test
A.
Class A{
public:
~A(){cout << "Destructor" << endl:}
}
int test()
{
A a;
free(&a);
return 0;
}
after the program run, it seems good, and print out Destructor
but after I insert one line into the func, the pgram crash
int test()
{
A a
free(&a);
cout << "test " << endl;
return 0;
}
h*****g
发帖数: 944
19
来自主题: JobHunting版 - C++里get array size的问题
C++里是不是现在没有现成的get array size/length的function??
如果没有的话,我在网上看到了一个code
#include
template char (&array(T(&)[N]))[N];
#define length(a) (sizeof a / sizeof a[0])
int main()
{
int a[10];
std::cout << sizeof array(a) << '\n';
std::cout << length(a) << '\n';
}
请问这个code对所有的data type都work吗? 我试试了,好象是可以的。中间有什么错
误吗?
h*****g
发帖数: 944
20
这两个iterator有什么区别?似乎这两个还是有细微差别的
比如 code1:
vector::reverse_iterator reverseIterator;
for(reverseIterator=integers.rbegin()reverseIterator!=integers.rend();++
reverseIterator)
cout<<*reverseIterator<<' ';
如果把iterator的type换成const_reverse_iterator, 他就会有compiling error:
Code 2:
vector::const_reverse_iterator reverseIterator;
for(reverseIterator=integers.rbegin()reverseIterator!=integers.rend();++
reverseIterator)
cout<<*reverseIterator<<' ';
但是稍微改动一下,他就work了, code3:
vector<
h**6
发帖数: 4160
21
来自主题: JobHunting版 - 面经: bloomberg 电面
赞考虑周到
一般来说,-x = ~x+1
只有最小负整数是个例外,-x = x,加负号后仍然是其本身。
short a = -32768;
short b = -a;
cout< cout< a和b都是-32768
I*****y
发帖数: 602
22
来自主题: JobHunting版 - C++: what is the output? How to interpret it?
gcc 4.1.2 under linux 2.6.18下边编译通过,运行结果是:
xyz
我的解释是cout< c2输出错误的原因是c2是个null pointer。
o**s
发帖数: 65
23
来自主题: JobHunting版 - C++ Q36: derivation specification (B8_9)
the testcase is correct, b is the right answer.
But for this one:2. in a class, the same
function can only appear once, and accesibility won't affect this. As A's :
void f(int) goes into B, you can not have another void f(int) in B.
I have different opinion.
class A {
void f(int){
cout << "A::f()" << endl;
}
public:
void gg(){
f(10);
}
};
class B : public A {
public:
void f(long);
void f(int){
cout << "B::f()
b********e
发帖数: 693
24
来自主题: JobHunting版 - C++ Q36: derivation specification (B8_9)
B is wrong, please see following test case
A *a = new B(). when call a->f(1), it print out B.
class C;
class A {
virtual void f(int) {cout << "A ";};
public:
friend class C;
};
struct B : public A {
public:
void f(long){};
void f(int){cout << "B f";};
};
class C{
public:
void test(){
A *a = new B();
a->f(1);
}
};
c**********e
发帖数: 2007
25
来自主题: JobHunting版 - C++ Q42: (C22)
extern void print(int *ia, int sz); // { cout << "extern" << endl; }
void print(int *array, int size); // { cout << "space" << endl; }
Does the sample code compile?
a) Yes, it does.
b) No, there are 2 functions named print.
c) No, the function name print cannot be extern.
d) No, there are 2 functions named print that have the same signature.
D***h
发帖数: 183
26
来自主题: JobHunting版 - Amazon onsite面试的惨痛经历
how about this. I test it seems ok.
#include
#include
using namespace std;
void num2alpha(int n){
vector vec;
vector::reverse_iterator it;
int i=n;
if(n==0)
vec.push_back('a');
else{
while(i>0){
vec.push_back('a'+n%26);
i=n/26;
n = n/26 -1;

}
}
for(it=vec.rbegin();it!=vec.rend();it++)
cout<<*it;
cout<
}
b*******y
发帖数: 32
27
来自主题: JobHunting版 - Amazon onsite面试的惨痛经历
你的结果和我的一样,
============================
#include
#include
using namespace std;
void num2str(int num) {
vector str;
vector::reverse_iterator rit;
const int step = 3;
int value;
bool first = true;
while(num != -1) {
value = num % step;
str.push_back('a'+value);
num = num / step -1;
}
for (rit = str.rbegin(); rit < str.rend(); ++rit)
cout << *rit;
cout< }
int NumString() {
for (int i = 0;
i**********e
发帖数: 1145
28
来自主题: JobHunting版 - Amazon onsite面试的惨痛经历
你的解法很好!
也可以用递归,这样就可以直接打印,不需要储存空间。
因为递归本身就好比stack,这样就能从后到前的秩序把字符串显示出来。
void num2StrHelper(int n) {
if (n == 0) return;
num2StrHelper((n-1)/26);
cout << (char)('a'+(n-1)%26);
}
void num2str(int n) {
num2StrHelper(n/26);
cout << (char)('a'+n%26);
}
不知道大家有没有发现,其实这题如果改成:
1->A
2->B
...
27->AA
...
这题就会简单好多。因为直接把10进制转换成26进制就得了。
一些常见面试题的答案与总结 -
http://www.ihas1337code.com
e**********6
发帖数: 78
29
来自主题: JobHunting版 - Amazon onsite面试的惨痛经历
第三题感觉就是:个位数从0-25,其余位都是1-26;把十进制转换为26进制。特殊处理
个位即可。。
这么写应该就行:
stack mys;
mys.push('A'+val%26);
val/=26;
while(val){
val--;
mys.push('A'+val%26);
val/=26;
}
while(!mys.empty()){
cout< mys.pop();
}
cout<
x****k
发帖数: 2932
30
来自主题: JobHunting版 - Apple的一些C++概念题
A general template:
template struct X
{ void f() { cout << "Primary template" << endl; } };
Partial specialized template(only for template class and struct, not for
funtion)
template struct X
{ void f() { cout << "Partial specialization 1" << endl;
} };
l********n
发帖数: 54
31
来自主题: JobHunting版 - 问个c++题
有一个类
class A
{
};
要使得下面的code能够编译
int main(void)
{
A a;
cout< return 1;
}
并且cout< 问需要在这个类里添加什么functions,如何实现。
============
应该是要对<<进行operator overloading
ostream& operator<< (const ostream& out, const A& a);
不过不知道如何实现。
PS: 建议用用这个工具,这样大家可以讨论code起来比较方便。
http://www.ideone.com/kNSiq
l*******y
发帖数: 1498
32
来自主题: JobHunting版 - 问个c++题
你这个链接里的只能 A<
i**********e
发帖数: 1145
33
来自主题: JobHunting版 - 请教一道面试题
Idea: Use recursion to solve. Recursion is like printing all possible
combination from a list of integers. To avoid duplicate result sets, sort
the candidate array first.
This solution assumes that the candidate array does not have any duplicates.
Remove all duplicates first if the candidate array does have duplicates.
void printSum(int candidates[], int index[], int n) {
for (int i = 1; i <= n; i++)
cout << candidates[index[i]] << " ";
cout << endl;
}
void solve(int target, int sum, int
w****g
发帖数: 206
34
/thinking in C++/第三章最后一个程序,硬是看不懂, 请高手指点一下:

//: C03:FunctionTable.cpp
// Using an array of pointers to functions
#include
using namespace std;
// A macro to define dummy functions:
#define DF(N) void N() { \
cout << "function " #N " called..." << endl; }
DF(a); DF(b); DF(c); DF(d); DF(e); DF(f); DF(g);
//以上是和前一句, 宏定义一起的么? 怎么解释?
void (*func_table[])() = { a, b, c, d, e, f, g };
//以上function定义怎么理解,a,b,...g,是arguments还是statments?
int main() {
... 阅读全帖
t*****j
发帖数: 1105
35
来自主题: JobHunting版 - C++问题2
char name[1000];
int age;
for (;;) {
std::cout << "Name: ";
std::cin >> name;
std::cout << "Age: ";
std::cin >> age;
std::cin.ignore(INT_MAX, '\n');
}
这最后一句 ignore到底是干嘛的,说是为了忽略非数字字符?干嘛要加这句?请讲解
下,谢谢!
l*******o
发帖数: 791
36
来自主题: JobHunting版 - c++ 程序一问
楼上说的对。
问题出现在你的test函数,test函数接受的是一个以值传递的指针。比如说一个经典的
swap(int a, int b)的例子,必须写成swap(int * a, int * b)或者引用才能改变外
界传入函数参数的值。同理如果你想改变一个指针的值,你需要用对一个指向这个指针
的指针进行操作,
所以test必须写成
void test (char * * p)
{
*p = new char[10];
memset((*p), 'A', 10);
}
然后main函数写成
int main(int argc, char *argv[])
{
char *k;

test(&k);
cout << k << endl;
}
不过一般倾向于使用引用即reference这样你就不会混淆,reference版本如下
void test( char * & p )
{
p = new char[10];
memset(p, 'A', 10);
int main(int argc, char *argv[])
{... 阅读全帖
r*****n
发帖数: 20
37
来自主题: JobHunting版 - Google的面经
恩 make sense
题意理解有误
这个题有比O(n^2)好的算法么?
写了一下O(n^2) 测了一下349901词的一个dichttp://www.math.sjsu.edu/~foster/dictionary.txt 要跑5-6分钟
return:
stekelenburg,hohohohohoho
代码如下
int myfunc(string a, string b){
return a.size()>b.size();
}
void foo(vector arr){

if(!arr.size())
return;
//step 1. sort w.r.t. lentgh of each word O(nlogn)
sort(arr.begin(), arr.end(), myfunc);

//step 2. compute signature for each word
vector sig;
for(long i=0; i阅读全帖
c*****e
发帖数: 74
38
/*
How can we generate all possibilities on braces ?
N value has given to us and we have to generate all possibilities.
**Examples:**
1) if N == 1, then only one possibility () .
2) if N==2, then possibilities are (()), ()()
3) if N==3, then possibilities are ((())), (())(),()()(), ()(()) ...
Note: left and right braces should match. I mean )( is INVALID for the N==1
How can we solve this problem by using recurrence approach ?
*/
#include
using namespace std;
void PrintStack(deque&... 阅读全帖
b*****e
发帖数: 474
39
来自主题: JobHunting版 - facebook电话二面题目
// my solution using recursion + global variables
int a[] = { 2, 3, 5, 7, 10 }; // sorted coin denominations
int size = 5; // number of coin types
int partial[MAX]; // store partial solutions (coins) -
// sorted in descending order
int partialSize=0; // partial solution size (# of coins)
void print_current_solution() {
for (int i=0; i cout << endl;
return;
}
// do ... 阅读全帖
b*****e
发帖数: 474
40
来自主题: JobHunting版 - facebook电话二面题目
// my solution using recursion + global variables
int a[] = { 2, 3, 5, 7, 10 }; // sorted coin denominations
int size = 5; // number of coin types
int partial[MAX]; // store partial solutions (coins) -
// sorted in descending order
int partialSize=0; // partial solution size (# of coins)
void print_current_solution() {
for (int i=0; i cout << endl;
return;
}
// do ... 阅读全帖
B********n
发帖数: 384
41
来自主题: JobHunting版 - Facebook Hacker Cup
觉得有道理,感觉分析清楚了程序很简单。另外输入很小,用brute force也没什么问
题。M <= 9, 9! = 362880,可以作为验证。
bool StringCompare (string s1, string s2)
{
return ( (s1+s2) < (s2+s1) );
}
void PrintLeastOrder(vector words)
{
sort(words.begin(), words.end(), StringCompare);
for (int i = 0; i < words.size(); i++)
cout << words[i].c_str();
cout << "\n";
}
Output
cupfacebookforhackerstudentsstudious
duzklvrawqrc
dyroiymybeaxeyubxzdr
bwjibwjibwjijp
dcyihopjijliuiuy

This
i**********e
发帖数: 1145
42
来自主题: JobHunting版 - fb 面经
For number 1, the problem of proving the statement sounds MORE interesting..
. hmm..
My solution using character pointer manipulation.
#include
using namespace std;
void printCharCounts(const char *in, char out[]) {
int count = 1;
char *pOut = out;
const char *pIn = in;
while (*pIn) {
if (*pIn == *(pIn+1)) {
count++;
} else {
*pOut++ = '0' + count;
*pOut++ = *pIn;
count = 1;
}
pIn++;
}
*pOut = '\0';
}
int main() {
char str[100] = "... 阅读全帖
x*********s
发帖数: 2604
43
void numberOfSum(int sum, vector v, int last)
{
if(sum == 0)
{
for (int i = 0; i < v.size(); i++)
{
cout< }
cout< return;
}
for (int i = 1; i <= sum; i++)
{
if(sum - i >= 0 && i >= last)
{
vector temp = v;
temp.push_back(i);
numberOfSum(sum-i,temp,i);
}
}
}
i**9
发帖数: 351
44
来自主题: JobHunting版 - 找硬币的经典问题
This is a classic backtracking algorithm question.
int coins[3]={2, 3, 5}
void printCombinations(int sum,int number){
static int combinations[MAX_SIZE];//MAX_SIZE=sum/2;
if(sum ==0){
printArray(combinations,number);
}
else{
if(sum >0){
for(int i=0;i<3;i++){
combinations[number]=coins[i];
printCombinations(sum-coins[i],number+1);
}
}
}
}
void printArray(int a[],int length){
for(int i=0;i std::c... 阅读全帖
i**********e
发帖数: 1145
45
来自主题: JobHunting版 - 问道很难的面世题
其实我之前的帖子有一些错误.
例如,我的假设是integer是错的.
liveInBoston 也犯了这个错误,题目说 N, D, C, F is real numbers.
另外,我也漏了一些细节部分.
例如,忘了处理当中间没油了的情况.
但是基本思路还是对的.
我已经把我解这道题的详细思路 记录在这里:
http://www.ihas1337code.com/2011/01/nuts-in-oasis-interview-que
Below is my output for the sample test cases:
N: 1 D: 1 C: 1 F: 1 maxNuts: 0
N: 1 D: 2 C: 1 F: 1 maxNuts: 0
N: 1 D: 0.25 C: 1 F: 1 maxNuts: 0.75
N: 2 D: 1 C: 1 F: 1 maxNuts: 0.333333
N: ... 阅读全帖
E*****7
发帖数: 128
46
来自主题: JobHunting版 - a very difficult interview question
Try this one in C++.
(1) Compute N to the power of M;
(2) Insert each of the generated result to std::map as the key of the key-value pair. std::map sorts the key exactly as required by the interview question when each key-value pair is inserted into it. In my code, the "value" is just a placeholder.
#include
#include
std::map SeriesNumber;
static unsigned value = 1;
void NtoM(unsigned n, unsigned m)
{
unsigned result = n;
for (unsigne... 阅读全帖
i**********e
发帖数: 1145
47
来自主题: JobHunting版 - 问道 facebook 面试题
其实不递归 代码或许会更简单些
void outputJSon(istream &in) {
bool newLine = false;
bool inBracket = false;
int indentLevel = 0;
while (in) {
char c = in.get();
if (newLine) {
cout << endl << setw(indentLevel) << c;
newLine = false;
}
else {
cout << c;
}
if (c == '{') {
indentLevel += TAB_SPACE;
newLine = true;
} else if (!inBracket && c == ',') {
newLine = true;
} else if (c == '}') {
newLine = true;
} else if (c == '[') {
... 阅读全帖
g**u
发帖数: 583
48
来自主题: JobHunting版 - Google Onsite 面经
用stl的priority_queue写了下multi-way merge, 请大家拍砖。
其中: myPair的第一个就是要存储的值, 第二个表示ownership.
/*
*multiple way merge using the priority_heap
*/
#include "vector"
#include "queue"
class myPair{
friend std::ostream & operator<<(std::ostream & out, const myPair &p)
{
out<<" ( "< return out;
}
public:
myPair(int x, int y):_first(x),_second(y)
{
}
bool operator >(const myPair & p)const
{
return this->_fir... 阅读全帖
z*******0
发帖数: 30
49
来自主题: JobHunting版 - A公司的面经
int a;
int b;
int fibo1(int n)
{
if (n == 0) return 0;
if (n == 1 || n == 2) return 1;
a = 1; b = 1;
return fiboR(3, n);
};
int fiboR(int x, int n)
{
int c = a + b;
a = b;
b = c;
if (x == n)
{
cout < return b;
}
int v = fiboR(x+1, n);
cout < return v;
};
l*****a
发帖数: 14598
50
来自主题: JobHunting版 - A公司的面经
Fibonacci(0,1,k);
void Fibonacci(int a,int b,int k)
{
cout< if(k>1) Fibonacci(b,a+b,k-1);
return;
}
void Fibonacci(int a,int b,int k)
{
if(k>1) Fibonacci(b,a+b,k-1);
cout< return;
}
why need static variables?
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)