IQ Test

Description:

Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given numbers finds one that is different in evenness, and return a position of this number.

! Keep in mind that your task is to help Bob solve a real IQ test, which means indexes of the elements start from 1 (not 0)

Examples :

IQ.Test("2 4 7 8 10") => 3 // Third number is odd, while the rest of the numbers are even

IQ.Test("1 2 1 1") => 2 // Second number is even, while the rest of the numbers are odd

using System;
using System.Linq; public class IQ
{
public static int Test(string numbers)
{
//Your code is here...
int[] array = numbers.Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
int evenCount = array.Count(x => x % == );
int number = ;
if (evenCount > )
{
for (int i = ; i < array.Length; i++)
{
if (array[i] % == )
{
number = i + ;
break;
}
}
}
else
{
for (int i = ; i < array.Length; i++)
{
if (array[i] % == )
{
number = i + ;
break;
}
}
}
return number;
}
}

其他人的解法

int类的静态方法 public static int Parse(string s);
需要注意groupBy的返回值

using System;
using System.Linq; public class IQ
{
public static int Test(string numbers)
{
var ints = numbers.Split(' ').Select(int.Parse).ToList();
var unique = ints.GroupBy(n => n % ).OrderBy(c => c.Count()).First().First();
return ints.FindIndex(c => c == unique) + ;
}
}


IQ Test的更多相关文章

  1. CSU 1597 薛XX后代的IQ

    Description 薛XX的低IQ是个令人头疼的问题,他的队友深受其害.幸运的是,薛XX非常有钱,所以他买了一些可以提高他的后代的IQ的药.这种药有三个属性,A,B和P.当薛XX使用这种药的时候, ...

  2. Ejabberd 插件开发 --- IQ截获与处理

    ejabberd的组件开发其实是非常简单的,只要遵循其gen_mod规范,添加iq处理函数就可以了.下面一步步教大家如何开发ejabberd组件. 首先,最好是自己编译ejabberd源码,这样的话把 ...

  3. 少睡与吸烟影响IQ

        导读:据英国<每日邮报>报道,根据科学家一项最新研究发现,一晚的糟糕睡眠,对大脑可能产生很大损害,就等同头部遭到了一次严重的撞击.长期睡眠不好会造成智力下降,请看[科学探索]揭秘: ...

  4. Sybase IQ如何将大文件数据迅速加载到数据库

    试想一下,如果一个文件5G.10G甚至更大.如何将它迅速地加载到数据库指定的表呢?我们看看Sybase IQ是如何迅速地将表的数据加载到数据库的. 数据文件格式: 1440,2011-01-09 00 ...

  5. Sybase IQ导出文件的几种方式

    IQ有四种方法,将表的数据导出为文本文件:1.重定向 SELECT * FROM TABLE1 ># D:MYDATATABLE1.TXT -- 文件生成在执行语句的客户端上 2.通过选项导出 ...

  6. iq 格式分析

    po iq {type:1 name:iq xml:"<iq xmlns="jabber:client" to="testhjy@ecouser.net/ ...

  7. IQ一个人的智力和对科学知识的理解掌握程度。 EQ对环境和个人情绪的掌控和对团队关系的运作能力。 AQ挫折商 一个人面对困境时减除自己的压力、渡过难关的能力。

    IQ: Intelligence Quotient 智商 一个人的智力和对科学知识的理解掌握程度. EQ: Emotional Quotient 情商 一个人对环境和个人情绪的掌控和对团队关系的运作能 ...

  8. Smack IQ包的扩展

    前几天一直很烦躁,怎么扩展smack的IQ包堵了我好久,今天静下心来看了下smack的源码,把这个问题解决了.下面给出步骤: 如果我们要扩展一个如下所示的IQ包: <iq id="00 ...

  9. IOS Xmpp的Iq发送和解析之请求讨论组成员

    #pragma mark - 获取讨论组成员 - (void)getDiscussionMemberInfoWithSendIq:(discussionModel *)data { NSXMLElem ...

随机推荐

  1. 转:jQuery对象与dom对象的转换

    jQuery对象与dom对象的转换 发布时间:September 20, 2007 分类:JavaScript <新站上线的手记> <Discuz!多附件上传选择框之jQuery版& ...

  2. 07_XPath_01_入门

    [工程截图] [person.xml] <?xml version="1.0" encoding="UTF-8"?> <students> ...

  3. 2015/7/6 (!长期更新!)C语言从零——张呵呵

    随即呈上! By    He_He _S 小组 @成都七中高新OI2015

  4. sicily 1200欢迎提出优化方案

    水题来的……我的做法是用a[10]数组表示每个数字出现的次数. 1200. Stick 限制条件 时间限制: 1 秒, 内存限制: 32 兆 题目描述 Anthony has collected a ...

  5. 九度OJ 1214 寻找丑数【算法】

    题目地址:http://ac.jobdu.com/problem.php?pid=1214 题目描述: 把只包含因子2.3和5的数称作丑数(Ugly Number).例如6.8都是丑数,但14不是,因 ...

  6. 1.MySQL的安装(linux Ubuntu环境下)

    首先先检验一下系统中是否已经安装有mysql: deamon@deamon-H55M-S2:~$ sudo netstat -tap | grep mysql [sudo] password for ...

  7. CentOS7 firewall的使用

    # 查看区域 firewall-cmd --get-zones # 查看默认区域 firewall-cmd --get-default-zone # 给区域添加永久性服务 firewall-cmd - ...

  8. QML鼠标区域控制

    鼠标操作使用很多,下面给出一个示例: import QtQuick 2.4 import QtQuick.Controls 1.3 import QtQuick.Window 2.2 import Q ...

  9. 细说 ASP.NET Cache 及其高级用法

    许多做过程序性能优化的人,或者关注过程程序性能的人,应该都使用过各类缓存技术. 而我今天所说的Cache是专指ASP.NET的Cache,我们可以使用HttpRuntime.Cache访问到的那个Ca ...

  10. c#抽象工厂类

    抽象工厂类的结构如下: 工厂 a=new 1工厂 抽象类A aa=a.createA() aa.create()==类A1.create() 抽象类B bb=a.createB() bb.get()= ...