笔试
两道题:
#include <iostream>
using namespace std;
//struct Node {
// int val;
// Node* next;
// Node(int x) : val(x), next(NULL) {}
//};
//
//class Test {
//public:
// void NodeClear(Node* node/*in*/) {
// if (NULL == node)
// {
// return;
// }//输入判断,为空直接退出。
// Node* pCurrent = node;
// Node* pNext = node->next;
// while (pNext->next != NULL)
// {
// pCurrent->val=pNext->val;
// pCurrent= pNext;
// pNext= pNext->next;
// }
// pCurrent->val = pNext->val;
// pCurrent = NULL; //现在它是最后一个。
// free(pNext);
// pNext = NULL;
//
// }
//};
/*
C++生成格雷码。
2020.3.30 21:48
0 1 1 0 对称的顺序加入上一级的字符串。
如: 0 1
00 01 11 10
000 001 011 010 110 111 101 100
*/
#include<iostream>
#include<string>
#include<vector>
using namespace std;
class Solution {
public:
vector<int> circularPermutation(int n, int start) {
string* data=new string[pow(2,n)];
for (int i = 1; i <= n; i++) {
if (i == 1) {
data[0] += "0";
data[1] += "1";
}
else {
for (int j = pow(2, i)-1; j >=0 ; j = j - 2) {
data[j] = data[(j-1)/2];
data[j - 1] = data[(j - 1) / 2];
}
for (int j1 = 0; j1 < pow(2,i-1); j1++) {
if (j1 % 2 == 0) {
data[j1 * 2] += "0";
data[j1 * 2 + 1] += "1";
}
else {
data[j1 * 2] += "1";
data[j1 * 2 + 1] += "0";
}
}
}
}
vector<int> a1;
for (int i = 0; i < (int)(pow(2, n));i++) {
int a2 = 0;
for (int i2 = 0; i2 < data[i].size(); i2++) {
a2 += ((int)data[i][i2] - 48) * (pow(2, data[i].size()-i2-1));
}
a1.push_back(a2);
}
delete[]data;
while (a1[0] != start) {
a1.push_back(a1[0]);
a1.erase(a1.begin());
}
return a1;
};
};
int main()
{
Solution s;
int n = 0;
int start = 0;
cin >> n;
cin >> start;
vector<int> a3 = s.circularPermutation(n,start);
for (auto e : a3) {
cout << e << " ";
}
return 0;
}
面试
1.问了计算机视觉的实验,我的一个项目。
2.两道题目:
/*
1.数组作为形参传入时,退化为指针。
2.子类对象会先调用父类的构造函数,然后是子类的构造函数。
*/
#include<iostream>
using namespace std;
//double a[100];
//int func1(double p[100]) { //这个p会退化成指针。
// return sizeof(p);
//}
//int func2(double p[100]) {
// return sizeof(a);
//}
//int main() {
// cout << func1(a)<<endl;
// cout << func2(a);
// return 0;
//}
class CA {
public:
~CA() {
cout << "~class A" << endl;
}
};
class CB :public CA {
public:
~CB() {
cout << "~class B" << endl;
}
};
int main() {
CA a;
CB b;
CB* c = new CB();
delete c;
return 0;
}
//输出是 ~B ~A ~B ~A ~A
3.问我的职业规划。
凉了。