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. PHP基础笔记汇总

    一.PHP简介PHP:超文本预处理器(译者注:PHP: Hypertext Preprocessor,递归命名)PHP 是一种服务器端的脚本语言,类似 ASPPHP 文件的文件后缀是 ".p ...

  2. ASP.NET常用代码汇总

    1. 打开新的窗口并传送参数: 传送参数:response.write("<script>window.open('*.aspx?id="+this.DropDownL ...

  3. NSDateFormatter中时间格式串的含义

    a: AM/PM (上午/下午) A: 0~86399999 (一天的第A微秒) c/cc: 1~7 (一周的第一天, 周天为1) ccc: Sun/Mon/Tue/Wed/Thu/Fri/Sat ( ...

  4. WinForm程序安装、发布流程

    一  签名 所谓签名就是给应用程序一个身份,申请一个专利.签名的时候需要选择证书.就向我们上学一样,得奖了老师给你发个证书.如果不进行签名,杀毒软件会把你打包后的exe文件作为病毒处理. 签名的步骤: ...

  5. 获取屏幕分辨率(C/C++)

    C/C++获取屏幕分辨率的方法 int main(int argc, char* argv[]) { // 需要添加头文件: // #include <Windows.h> system( ...

  6. sqoop简单import使用

    一.sqoop作用? sqoop是一个数据交换工具,最常用的两个工具是导入导出. 导入导出的参照物是hadoop,向hadoop导数据就是导入. 二.sqoop的版本? sqoop目前有两个版本,1. ...

  7. eclipse代码编辑快捷键

    代码提示(代码助手):alt + / 如输入e后按alt+/,则会出现以e开头的相关方法,写代码时经常按按 删除一行代码: 光标移动到该行任意位置,按ctrl+d 剪切:ctrl+x 复制:ctrl ...

  8. 装黑苹果的那些事儿(以ThinkpadE540为例)

    苹果系统,有着比window更好的安全性和方便性,更重要的事,没有MAC系统环境,进行iOS开发,是很麻烦的,对新手来说,是很懊恼的一件事.但是白苹果像件奢侈品,吾等常人,很难有经济消费.如是黑苹果是 ...

  9. linux rm 命令

    1.命令格式: rm [选项] 文件… 2.命令功能: 删除一个目录中的一个或多个文件或目录,如果没有使用- r选项,则rm不会删除目录.如果使用 rm 来删除文件,通常仍可以将该文件恢复原状. 3. ...

  10. 最简单的耗时组件(窗口activity里面放一个progressBar)

    ①.先定义一个activity package com.example.administrator.actionbardemo; import android.app.Activity; import ...