2014-05-10 07:06

题目链接

原题:

Suppose you have a collection of collection
Eg : CEO-> Vps-> GMs ->..
CEO will contain collection of VP's, VP's will have collection of GM's and so on.
Suppose you need to find a particular GM is the alias is given. Write a linq query to get the employee details if the employee alias is given.
Hint : Use Recursion + Linq

题目:如果CEO手下有很多总监,总监手下有很多总经理,依此类推。那么通过一个名字和一个头衔,要如何找到符合条件的人?用递归和LINQ实现。

解法:这明显是C#问题吧。C#我勉强懂点基本语法,LINQ则完全不会,所以我只能用递归了。

代码:

 // http://www.careercup.com/question?id=4840369632051200
// I believe this is not a typical interview question. You must've told them you know LINQ, before you're given this one.
// I've never learnt LINQ before, only basic knowledge of C# is not enough to solve this problem.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace CSharp
{
class Person
{
public string title;
public string alias;
public List<Person> subordinate; public Person(string title, string alias)
{
this.title = title;
this.alias = alias;
subordinate = new List<Person>();
}
} class Solution
{
Person search(string title, string alias, Person source) {
if (source.title == title) {
return source.alias == alias ? source : null;
} Person result;
foreach(Person sub_source in source.subordinate)
{
result = search(title, alias, sub_source);
if (result != null)
{
return result;
}
} return null;
}
}
}

Careercup - Microsoft面试题 - 4840369632051200的更多相关文章

  1. Careercup - Microsoft面试题 - 6314866323226624

    2014-05-11 05:29 题目链接 原题: Design remote controller for me. 题目:设计一个遥控器. 解法:遥控什么?什么遥控?传统的红外线信号吗?我只能随便说 ...

  2. Careercup - Microsoft面试题 - 6366101810184192

    2014-05-10 22:30 题目链接 原题: Design database locks to allow r/w concurrency and data consistency. 题目:设计 ...

  3. Careercup - Microsoft面试题 - 24308662

    2014-05-12 07:31 题目链接 原题: I have heard this question many times in microsoft interviews. Given two a ...

  4. Careercup - Microsoft面试题 - 5700293077499904

    2014-05-12 00:02 题目链接 原题: For a given map (ie Bing map) given longitude/latitude/ how would you desi ...

  5. Careercup - Microsoft面试题 - 5204967652589568

    2014-05-11 23:57 题目链接 原题: identical balls. one ball measurements ........ dead easy. 题目:9个看起来一样的球,其中 ...

  6. Careercup - Microsoft面试题 - 5175246478901248

    2014-05-11 23:52 题目链接 原题: design an alarm clock for a deaf person. 题目:为聋人设计闹钟? 解法:聋人听不见,那么闪光.震动都可行.睡 ...

  7. Careercup - Microsoft面试题 - 5718181884723200

    2014-05-11 05:55 题目链接 原题: difference between thread and process. 题目:请描述进程和线程的区别. 解法:操作系统理论题.标准答案在恐龙书 ...

  8. Careercup - Microsoft面试题 - 5173689888800768

    2014-05-11 05:21 题目链接 原题: Complexity of a function: int func_fibonacci ( int n) { ) { return n; } el ...

  9. Careercup - Microsoft面试题 - 6282862240202752

    2014-05-11 03:56 题目链接 原题: Given an integer array. Perform circular right shift by n. Give the best s ...

随机推荐

  1. JavaScript的匿名函数和模块化的使用方法

    对于开发人员来说,很多时候我们都会涉及到JavaScript的使用,而在使用过程中,最令人沮丧的就是变量没有相应的使用范围. 在开发中,对于任何变量.数组.函数.对象等,只要不在函数的内部,都会被默认 ...

  2. STL使用sort注意的问题

    结构体使用sort算法时,重载operator<(..).如果我们按下面这样写 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ...

  3. placeholder插件及placeholder默认颜色修改

    $.fn.placeHolder = function(){ $(this).each(function(i, el) { var self = $(el); if ($.browser.msie & ...

  4. CentOS 6.x版本升级Mysql

    首先确定一下自己的DNS  vi /etc/resolv.conf    我一般为114.114.114.114 #-----------------------------CentOS 6.x版本升 ...

  5. c#使用DocX添加多级标题

    博客转移到 http://jacean.github.io/ 继续分享编程经验 先上效果.可以生成多级标题,但是不能生成1,1.1,1.2这样的自动序列, 只是这样的效果. 实现方法是给Paragra ...

  6. MongoDB的安装小结

    正在做毕业设计,想尝试着用mongoDB来做数据库,之前没有接触过,然后,就在网上找资料,自己捣鼓,弄了好久才算上真正的把它安上,好心累.... 网上有很多安装教程,大同小异,这里呢,我只是想记录一下 ...

  7. MapReduce框架Partitioner分区方法

    前言:对于二次排序相信大家也是似懂非懂,我也是一样,对其中的很多方法都不理解诶,所有只有暂时放在一边,当你接触到其他的函数,你知道的越多时你对二次排序的理解也就更深入了,同时建议大家对wordcoun ...

  8. php获取图片宽高等属性

    <?php function getImageInfo($image) {     $imageInfo = getimagesize($image);     if ($imageInfo ! ...

  9. PHP-POSIX正则表达式函数

    1.ereg() 格式:ereg("条件",<原始字符串>) ereg()查找字符串,是严格区分大小写的 <?php $string="apples a ...

  10. ASP.NET MVC5学习笔记之Filter提供体系

    前面我们介绍了Filter的基本使用,但各种Filter要在合适的时机运行起来,需要预先准备好,现在看看ASP.NET MVC框架是怎么做的. 一.Filter集合 在ControlerActionI ...