Skip to content

Commit 6d0d70a

Browse files
committed
添加2011年准备面试和面试提解答代码
1 parent 3ccbb09 commit 6d0d70a

File tree

242 files changed

+16615
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

242 files changed

+16615
-0
lines changed

ms2011/Algorithm/lcs.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// dynamic plan for LCS problem 20111020 23:50~
2+
/* description:
3+
1. construct a matrix of LCS path
4+
2. find LCS in the path
5+
*/
6+
#include <iostream>
7+
#include <string>
8+
#include <vector>
9+
#include <stack>
10+
using namespace std;
11+
12+
typedef vector<int> row;
13+
typedef vector<row> Matrix;
14+
15+
void pathLCS(string A,string B,Matrix& c);
16+
void LCS(const Matrix& c);
17+
void printMatrix(const Matrix& c);
18+
19+
int main(int argc,char *argv[]){
20+
// find "ACD" & "BCS"
21+
string A = "ABCD";
22+
string B = "BACD";
23+
vector<int> t(A.size()+1,0);
24+
Matrix c(B.size()+1,t);
25+
printMatrix(c);
26+
pathLCS(A,B,c);
27+
printMatrix(c);
28+
LCS(c);
29+
return 0;
30+
}
31+
32+
void pathLCS(string A,string B,Matrix& c){
33+
cout << "path matrix.." << endl;
34+
int i,j;
35+
for (i=1; i<=B.size(); i++) {
36+
for (j=1; j<=A.size(); j++) {
37+
if (B[B.size()-i+1] == A[A.size()-j+1]) // reverse A & B
38+
c[i][j] = c[i-1][j-1] + 1;
39+
else if(c[i-1][j] > c[i][j-1]) c[i][j] = c[i-1][j];
40+
else c[i][j] = c[i][j-1];
41+
}
42+
}
43+
}
44+
45+
void LCS(const Matrix& c){
46+
// print all the path from bottom to up by dfs
47+
if(c.size() == 0) return;
48+
int m = c[0].size(), r = c.size(); // columns & rows
49+
int i(r),j(m);
50+
51+
}
52+
53+
void printMatrix(const Matrix& c){
54+
for (int i=0; i<c.size(); i++) {
55+
for (int j=0; j<c[i].size(); j++) {
56+
cout << c[i][j] << ' ';
57+
}
58+
cout << endl;
59+
}
60+
}
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+

ms2011/Algorithm/lcs.exe

45.9 KB
Binary file not shown.

ms2011/Algorithm/lcs.exe.stackdump

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Exception: STATUS_ACCESS_VIOLATION at eip=004014AE
2+
eax=00000001 ebx=00000004 ecx=00900338 edx=00000000 esi=00000000 edi=00000000
3+
ebp=0022CCC8 esp=0022CCA0 program=G:\career\code\Algorithm\lcs.exe, pid 2456, thread main
4+
cs=001B ds=0023 es=0023 fs=003B gs=0000 ss=0023
5+
Stack trace:
6+
Frame Function Args
7+
0022CCC8 004014AE (0022CD1C, 0022CD18, 0022CCEC, 0022CD17)
8+
0022CD38 004012C7 (00000001, 61243964, 009000F8, 61004BB9)
9+
0022CD68 61007038 (00000000, 0022CDA4, 61006980, 7FFD8000)
10+
End of stack trace

ms2011/BS/aly1.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// 不用任何循环语句,库函数求一个输入字符串的长度
2+
3+
#include <iostream>
4+
using namespace std;
5+
6+
int lens(char *s){
7+
if(*s == '\0') return 0;
8+
else return 1+lens(++s);
9+
}
10+
11+
int main(int argc,char *argv[])
12+
{
13+
char * s = argv[1];
14+
cout << lens(s) << endl;
15+
return 0;
16+
}

ms2011/BS/aly1.exe

22.1 KB
Binary file not shown.

ms2011/BS/dianp1.cpp

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// dianp1.cpp
2+
// 大众点评第1题
3+
// 描述:
4+
// Input: 一个n个数的数组,其中某个数字出现次数大于N/2;
5+
// Outpu: 找出那个数
6+
//
7+
8+
#include <iostream>
9+
#include <vector>
10+
using namespace std;
11+
12+
int findk(vector<int> a); // 计数法,连续相同则加,否则减
13+
int rfindk(vector<int> a,int s,int e); // 快排划分法,传值,以中间值划分的方式不适合
14+
int Partition(vector<int> &A, int s, int e );
15+
void QuickSort2( vector<int>& A, int p, int q );
16+
17+
int main()
18+
{
19+
int a[] = {1,2,3,2,2,2,5}; // test
20+
vector<int> v(a,a+7);
21+
cout << findk(v) << endl;
22+
cout << rfindk(v,0,7) << endl;
23+
return 0;
24+
}
25+
26+
int findk(vector<int> a){
27+
if (a.size() < 0) return -1; //设置记录找不到的状态;
28+
int i,vn(a[0]),cnt(1);
29+
for (i=1; i< a.size(); i++) {
30+
if(a[i] == a[i-1]) cnt ++;
31+
else cnt --;
32+
if(cnt == 0) vn = a[i];
33+
}
34+
return vn;
35+
}
36+
37+
int rfindk(vector<int> a,int s,int e){
38+
int r = Partition(a,s,e);
39+
if (e-s > a.size()/2) return a[(s+e)/2];
40+
if (e-r > r-s) rfindk(a,r+1,e);
41+
else rfindk(a,s,r-1);
42+
}
43+
44+
int Partition(vector<int> &A, int s, int e )
45+
{// Asending
46+
int p_pos,tmp,i,j;//中间点位置
47+
p_pos = s; //假设中间点位置在第一位
48+
//假设中间点值为第一位元素的值 注意中间点元素的值是确定的 假设第一位 但是中间点元素的正确位置需要我们找
49+
int pivot = A[p_pos];
50+
for(i=s+1; i<=e; i++){ //从第二位开始查找 发现i位元素小于中间点值
51+
if(A[i] < pivot){
52+
p_pos++; //中间点位置右移一位
53+
if(p_pos != i) swap<int>(A[p_pos],A[i]);//交换此刻中间点位置所在元素与第i位元素的值
54+
}
55+
}
56+
//此时已经找到中间点元素所在正确位置 将中间点元素位置的值与假设第一位为中间点值交换
57+
swap<int>(A[s],A[p_pos]);
58+
return p_pos; //返回该中间点位置
59+
}
60+
61+
void QuickSort2( vector<int>& A, int p, int q )
62+
{
63+
if( p < q )
64+
{
65+
int r = Partition(A, p, q);
66+
QuickSort2(A,p,r-1);
67+
QuickSort2(A,r+1,q);
68+
}
69+
}
70+
71+
72+
73+
74+
75+
76+
77+
78+
79+
80+

ms2011/BS/dianp1.exe

37.1 KB
Binary file not shown.

ms2011/BS/hulu.exe

44 KB
Binary file not shown.

ms2011/BS/hulu.exe.stackdump

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Exception: STATUS_ACCESS_VIOLATION at eip=61111AC8
2+
eax=00A80478 ebx=FFFFFFF8 ecx=3FFF811D edx=00000000 esi=00AA0000 edi=00A9FFFC
3+
ebp=0022CBE8 esp=0022CBDC program=G:\career\code\BS\hulu.exe, pid 5740, thread main
4+
cs=001B ds=0023 es=0023 fs=003B gs=0000 ss=0023
5+
Stack trace:
6+
Frame Function Args
7+
0022CBE8 61111AC8 (00A80478, 00A8047C, FFFFFFF8, 611289CB)
8+
0022CC18 00401D26 (00A8047C, 00A80474, 00A80478, 00402369)
9+
0022CC48 004023A3 (00A8047C, 00A80474, 00A80478, 00402341)
10+
0022CC78 0040241D (00A8047C, 00A80474, 00A80478, 00A80474)
11+
0022CC98 004025AA (00A8047C, 00A80474, 00A80478, 00401B57)
12+
0022CCC8 00402218 (0022CCF0, 00A80478, 0022CCE8, 610C9BBA)
13+
0022CD08 00401281 (00000001, 61180E48, 00000000, 0022D000)
14+
0022CD38 0040132C (00000001, 61243824, 00A800F8, 61004BB9)
15+
0022CD68 61007038 (00000000, 0022CDA4, 61006980, 7FFDF000)
16+
End of stack trace

ms2011/BS/hulu1.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// hulu1 笔试题- 50个数每次删除奇数/偶数最后剩下的数
2+
// by wrchow at 20110926
3+
4+
#include <iostream>
5+
#include <vector>
6+
using namespace std;
7+
8+
int oddeven50(int f){
9+
// 矩阵思想
10+
if(f == 1) cout << "Delete odd.." << endl;
11+
else cout << "Delete even.." << endl;
12+
vector<int> v;
13+
v.clear();
14+
int i=0;
15+
for (i=1; i<=50; i++) {
16+
v.push_back(i);
17+
}
18+
while (v.size() != 1) { // 数组不能循环删除
19+
vector<int> t;
20+
for (i=f; i<v.size(); i+=2){
21+
t.push_back(v[i]);
22+
cout << v[i] << ' ';
23+
} cout << endl;
24+
v.clear();
25+
v=t;
26+
}
27+
return v[0];
28+
}
29+
30+
int * postOrder() {
31+
32+
}
33+
34+
int main()
35+
{
36+
// ---------------------
37+
cout << "odd & even of 1..50 is :" // 32 & 1
38+
<< "odd = " << oddeven50(1)
39+
<< ", even = " << oddeven50(0) << endl; //后边的先调用
40+
// ---------------------
41+
42+
return 0;
43+
}

0 commit comments

Comments
 (0)