网易互娱-开发岗笔试题吐槽

今天2019.09.14,网易互娱笔试,编程题三道,三道题的题面全和“酒”有关,不是啤酒爱就是红酒,红酒还要考到醒酒。。。面试官是有多喜欢酒啊,如果能进面试,说不定玄学聊酒也能拿offer😂,下面是题面。
第一题,要求输入两个数组(顾客的要求数组、酒的品质数组),输出满意的顾客数。(此题纯逻辑,加逻辑就好了)
第二题,输入红酒的系列编号(二叉树的广度优先顺序),要求输出前序序列(其实是二叉树的中序序列)。(此题考二叉树的结构和遍历,今天第一次写二叉树代码,竟然写出来了😥
第三题,醒酒,bulabula,全都是酒,做到第三题就已经喝大了,没看懂。
笑屎。。。
附上第二题的代码,没来得及测试就交卷了,希望各路大神指点指点,不知道这个代码能不能AC出100%
#include<iostream>
#include<string>
#include<vector>
using namespace std;

typedef struct Node
{
	string strName;
	Node* pNode_L;
	Node* pNode_R;
}LBNode, *LBTree;

void DFS(LBNode* pNode, string& strRes)
{
	if (!pNode)
		return;
	DFS(pNode->pNode_L, strRes);
	strRes += pNode->strName;
	DFS(pNode->pNode_R, strRes);
}

string solve(string strIn)
{
	vector<string> vIns;
	string strTmp = strIn;
	while (!strTmp.empty())
	{
		int nIdx = strTmp.find(',');
		string strNodeName;
		if (nIdx != -1)
		{
			strNodeName = strTmp.substr(0, nIdx);
			strTmp = strTmp.substr(nIdx + 1, strTmp.length() - nIdx - 1);
		}
		else
		{
			strNodeName = strTmp;
			strTmp.clear();
		}
		vIns.push_back(strNodeName);
	}

	if (vIns[0] == "null")
		return "null";
	else
	{
		for (int i = vIns.size() - 1; i > 0; i--)
		{
			if (0 == i % 2)
			{
				if ("null" == vIns[i / 2 - 1])
				{
					return "null";
				}
			}
			else
			{
				if ("null" == vIns[i / 2])
				{
					return "null";
				}
			}
		}
	}

	vector<LBNode*> vNodes;
	for (int i = 0; i < vIns.size(); i++)
	{
		LBNode* pNode = new LBNode;
		pNode->strName = vIns[i];
		pNode->pNode_L = NULL;
		pNode->pNode_R = NULL;
		vNodes.push_back(pNode);
	}

	LBTree pTree = vNodes[0];
	for (int i = vNodes.size() - 1; i > 0; i--)
	{
		if (0 == i % 2)
		{
			if (vNodes[i]->strName != "null")
			{
				vNodes[i / 2 - 1]->pNode_R = vNodes[i];
			}
		}
		else
		{
			if (vNodes[i]->strName != "null")
			{
				vNodes[i / 2]->pNode_L = vNodes[i];
			}
		}
	}

	string strRes;
	DFS(pTree, strRes);
	return strRes;
}

int main()
{
	string strIn;
	getline(cin, strIn);
	cout << solve(strIn) << endl;
	system("pause");
	return 0;
}


#笔试题目##网易互娱#
全部评论
第二题我怎么做都只有58.33% 不知道哪出问题了
点赞 回复 分享
发布于 2019-09-14 23:06

相关推荐

大摆哥:刚好要做个聊天软件,直接让你帮他干活了
点赞 评论 收藏
分享
挣K存W养DOG:玩小红书玩的,觉得自己很幽默😅
点赞 评论 收藏
分享
评论
点赞
2
分享

创作者周榜

更多
牛客网
牛客企业服务