# 华为2016暑假实习机试题

#include <iostream>
#include <string>
using namespace std;

int main() {

string str;
cin >> str;
int len = str.size();
for (int i = 0; i < len; ++i)
if (str[i] <= 'Z' && str[i] >= 'A')
cout << str[i];

}

#include <iostream>
using namespace std;

int cmp(const void* a, const void* b) {
return (*(int*)a - *(int*)b);
}

int main() {

int n, i;
cin >> n;
if (n <= 0) return 1;
if (n == 1) {
cin >> n;
cout << n;
return 0;
}
int* arr = new int[n];
for (i = 0; i < n; ++i)
cin >> arr[i];
qsort(arr, n, sizeof(int), cmp);
cout << arr[0];
for (i = 1; i < n; ++i)
if (arr[i] != arr[i - 1])
cout << " " << arr[i];
}

#include <iostream>
#include <string>
using namespace std;

struct TreeNode
{
char val;
TreeNode* left;
TreeNode* right;
TreeNode() {};
TreeNode(char val) {
this->val = val;
this->left = this->right = NULL;
}
};

void buildTree(TreeNode*[], int);
int findDepth(TreeNode*[], char);
int getDepth(TreeNode*);
int max(int , int);

int main() {
string tree, nodes;
cin >> tree >> nodes;
int len = tree.size();
//int maxLevel = tree[len - 1] - '0'; // 由于最大层可能不是在最后一个字符，例如a1b2c2d3e3f3和b2c2d3e3f3a1是两棵完全一样的树
int maxLevel = 0;
for (int i = 1; i < len; i += 2) {
if ((tree[i] - '0') > maxLevel)
maxLevel = (tree[i] - '0');
}
TreeNode* trees[512] = {NULL}; // 最大层数为9层
int offset[9] = { 0 };
// 初始化树节点
for (int i = 0; i < len - 1; ++i) {
int level = tree[i + 1] - '0';
int levelBeg = _Pow_int(2, level - 1) - 1; // 每一层的起点为2^(level - 1) - 1
trees[levelBeg + offset[level - 1]] = new TreeNode(tree[i]); // 层数的下标从0开始
offset[level - 1]++;
i++; // 跳过数字
}
// 建树
buildTree(trees, maxLevel);
// 输出每个节点的深度
int test = nodes.size();
for (int i = 0; i < test - 1; ++i) {
cout << findDepth(trees, nodes[i]) << " ";
}
cout << findDepth(trees, nodes[test - 1]) << endl;
}

void buildTree(TreeNode* root[], int maxLevel) {
int total = _Pow_int(2, maxLevel) - 1;
for (int i = total / 2 - 1; i >= 0; --i) {
if (root[i] != NULL) {
root[i]->left = root[2 * i + 1];
root[i]->right = root[2 * i + 2];
}
}
}

int max(int a, int b) {
return a > b ? a : b;
}

int getDepth(TreeNode* root) {
if (root == NULL)
return 0;
return max(getDepth(root->left), getDepth(root->right)) + 1;
}

int findDepth(TreeNode* root[], char ch) {
bool flag = false;
for (int i = 0; i < 512; ++i)
if (root[i] != NULL && root[i]->val == ch)
return getDepth(root[i]);
return 0;
}

#include <iostream>
#include <string>
using namespace std;

int main() {
string str, testcase;
cin >> str;
cin >> testcase;
// 特殊情况判断
if (str.size() <= 1 || testcase.size() <= 0)
return -1;
int lvl[256];
for (int i = 0; i < 256; ++i)
lvl[i] = 10;	// 依题意最大层数不超过9层,且层数从1计起，其他不在树的节点默认为10
int lvlPos[256] = { 0 };	// 记录每个节点在所在层的位置，从1计起
int numPerLvl[11] = { 0 };	// 记录每一层的节点数，最大层数不超过9层,且层数从1计起
int len = str.size();
int tlen = testcase.size();

for (int i = 0; i < len - 1; i += 2) {
// 保留每个节点所在的层数
lvl[str[i]] = str[i + 1] - '0';
//	记录每个节点在所在层偏移的位置，按照完全二叉树的规律，节点的左右儿子为2*n-2, 2*n-1)
lvlPos[str[i]] = ++numPerLvl[lvl[str[i]]];
}

for (int i = 0; i < tlen; ++i) {
// 当节点不在树中，输出0
if (lvl[testcase[i]] == 10) {
cout << 0 << endl;
continue;
}
int depth = 1;
int level = lvl[testcase[i]];
int childNum = lvlPos[testcase[i]];
for (int k = lvl[testcase[i]]; k < 10; ++k) {
// 对于每一层的节点，计算由偏移量得出的儿子数目个数，若少于2*n-1则表示没儿子
childNum = 2 * childNum - 1;
if (numPerLvl[level + 1] < childNum) {
break;
}
else {	// 若有儿子，则继续往儿子方向迭代计数
depth++;
level++;
}
}
cout << depth << endl;
}
}

#### 2018华为暑假实习面试

2018-03-31 20:27:11

#### 华为2019届实习生面试

2018-03-31 15:51:19

#### 2018华为暑期实习

2018-04-10 20:53:52

#### 华为2017暑期实习生面试体会

2017-04-08 19:31:11

#### Android开发3D界面

2016-01-27 18:05:05

#### iOS百度地图的基本使用

2016-12-05 11:31:02

#### 自定义图片缩放组件—ImageZoomView

2013-07-03 16:30:45

#### 3D数学之-图形渲染数学

2015-06-17 21:38:54

#### QML Camera 摄像头拍照(带滑动条设置焦距)

2017-07-23 12:23:07

#### 图片等比例缩放

2012-07-25 12:16:58