IQ Test
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的更多相关文章
- CSU 1597 薛XX后代的IQ
Description 薛XX的低IQ是个令人头疼的问题,他的队友深受其害.幸运的是,薛XX非常有钱,所以他买了一些可以提高他的后代的IQ的药.这种药有三个属性,A,B和P.当薛XX使用这种药的时候, ...
- Ejabberd 插件开发 --- IQ截获与处理
ejabberd的组件开发其实是非常简单的,只要遵循其gen_mod规范,添加iq处理函数就可以了.下面一步步教大家如何开发ejabberd组件. 首先,最好是自己编译ejabberd源码,这样的话把 ...
- 少睡与吸烟影响IQ
导读:据英国<每日邮报>报道,根据科学家一项最新研究发现,一晚的糟糕睡眠,对大脑可能产生很大损害,就等同头部遭到了一次严重的撞击.长期睡眠不好会造成智力下降,请看[科学探索]揭秘: ...
- Sybase IQ如何将大文件数据迅速加载到数据库
试想一下,如果一个文件5G.10G甚至更大.如何将它迅速地加载到数据库指定的表呢?我们看看Sybase IQ是如何迅速地将表的数据加载到数据库的. 数据文件格式: 1440,2011-01-09 00 ...
- Sybase IQ导出文件的几种方式
IQ有四种方法,将表的数据导出为文本文件:1.重定向 SELECT * FROM TABLE1 ># D:MYDATATABLE1.TXT -- 文件生成在执行语句的客户端上 2.通过选项导出 ...
- iq 格式分析
po iq {type:1 name:iq xml:"<iq xmlns="jabber:client" to="testhjy@ecouser.net/ ...
- IQ一个人的智力和对科学知识的理解掌握程度。 EQ对环境和个人情绪的掌控和对团队关系的运作能力。 AQ挫折商 一个人面对困境时减除自己的压力、渡过难关的能力。
IQ: Intelligence Quotient 智商 一个人的智力和对科学知识的理解掌握程度. EQ: Emotional Quotient 情商 一个人对环境和个人情绪的掌控和对团队关系的运作能 ...
- Smack IQ包的扩展
前几天一直很烦躁,怎么扩展smack的IQ包堵了我好久,今天静下心来看了下smack的源码,把这个问题解决了.下面给出步骤: 如果我们要扩展一个如下所示的IQ包: <iq id="00 ...
- IOS Xmpp的Iq发送和解析之请求讨论组成员
#pragma mark - 获取讨论组成员 - (void)getDiscussionMemberInfoWithSendIq:(discussionModel *)data { NSXMLElem ...
随机推荐
- iOS 获取系统相册数据(不是调系统的相册)
Framework:AssetsLibrary.framework 主要目的是获取到系统相册的数据,并把系统相册里的照片显示出来. 1.创建一个新的项目: 2.将AssetsLibrary.frame ...
- 谱曲软件-MuseScore
谱曲软件-MuseScore 参考: 1.MuseScore官网 2.免费乐谱制作软体MuseScore
- sgu 108 Self-numbers II
这道题难在 hash 上, 求出答案很简单, 关键是我们如何标记, 由于 某个数变换后最多比原数多63 所以我们只需开一个63的bool数组就可以了! 同时注意一下, 可能会有相同的询问. 我为了防止 ...
- MySql启动提示:The server quit without updating PID file(…)失败
在网上找了很多 1.可能是/usr/local/mysql/data/rekfan.pid文件没有写的权限解决方法 :给予权限,执行 “chown -R mysql:mysql /var/data” ...
- leetcode problem 37 -- Sudoku Solver
解决数独 Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated ...
- 简单重置Centos服务器中Mysql的root密码
1.编辑MySQL配置文件my.cnf vi /etc/my.cnf #编辑文件,找到[mysqld],在下面添加一行skip-grant-tables [mysqld] skip-grant-tab ...
- spring-boot 整合redis作为数据缓存
添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>sp ...
- jquery中交替点击事件toggle方法的使用示例
jquery中交替点击事件toggle方法中有两个参数,分别是要交替执行的事件.如果不传参默认是显示隐藏功能,下面有个不错的示例,感兴趣的朋友可以参考下 复制代码代码如下: $('#clickId‘) ...
- 解决IE 下div与img重叠无法触发鼠标事件的问题
在IE下当我想在img标签上层显示一个div元素时,此时如果该div的background为空白(没有设置图片.或者颜色填充),会导致该div的鼠标事件失效:如果设置border为1px solid ...
- mysql更改数据文件目录及my.ini位置| MySQL命令详解
需求:更改mysql数据数据文件目录及my.ini位置. 步骤: 1.查找my.ini位置,可通过windows服务所对应mysql启动项,查看其对应属性->可执行文件路径,获取my.ini路径 ...