微软Code Hunt答案(00-05)——沉迷娱乐的我

昨天看到微软出的网游Code Hunt,导师也去北京开云计算会议了。o(∩_∩)o...哈哈,还不好好玩一吧,个人感觉不是一个模块比一个模块难的,Code Hunt是按功能划分。所以不要怕自己做不来,因为不同人特长不一样。像ACM都是分工合作的啦。废话不多,我们来总结一下前01-04的答案。希望对大家有帮助,纯属娱乐。还有很多可以优化的地方,欢迎一起来讨论!

注:语言C# 网页地址:https://www.codehunt.com/

     

chapter 00

00.02

using System;

public class Program {

public static int Puzzle(int x) {

return x+1;

}

}

00.03

using System;

public class Program {

public static int Puzzle(int x) {

return 2*x;

}

}

00.04

public class Program {

public static int Puzzle(int x, int y) {

return x+y;

}

}

chapter 01

01.01

using System;

public class Program {

public static int Puzzle(int x) {

return (-1)*x;

}

}

01.02

using System;

public class Program {

public static int Puzzle(int x) {

return x-2;

}

}

01.03

using System;

public class Program {

public static int Puzzle(int x) {

return x*x;

}

}

01.04

using System;

public class Program {

public static int Puzzle(int x) {

return 3*x;

}

}

01.05

using System;

public class Program {

public static int Puzzle(int x) {

return x/3;

}

}

01.06

using System;

public class Program {

public static int Puzzle(int x) {

return 4/x;

}

}

01.07

using System;

public class Program {

public static int Puzzle(int x, int y) {

return x-y;

}

}

01.08

using System;

public class Program {

public static int Puzzle(int x, int y) {

return x+2*y;

}

}

01.09

using System;

public class Program {

public static int Puzzle(int x, int y) {

return x*y;

}

}

01.10

public class Program {

public static int Puzzle(int x, int y) {

return x + y / 3;

}

}

01.11

using System;

public class Program {

public static int Puzzle(int x, int y) {

return (Math.Abs(x)>=Math.Abs(y)&&y!=0)?x/y:0;

}

}

01.12

using System;

public class Program {

public static int Puzzle(int x) {

return x%3;

}

}

01.13

using System;

public class Program {

public static int Puzzle(int x) {

return x%3+1;

}

}

01.14

using System;

public class Program {

public static int Puzzle(int x) {

return 10%x;

}

}

01.15

using System;

public class Program {

public static int Puzzle(int x, int y, int z) {

return (x+y+z)/3;

}

}

chapter 02

02.01

using System;

using System.Linq;

public class Program {

public static int[] Puzzle(int n) {

return Enumerable.Range(0, n).ToArray();

}

}

02.02

using System;

using System.Linq;

public class Program {

public static int[] Puzzle(int n) {

return Enumerable.Range(0, n).Select(x => x * n).ToArray();

}

}

02.03

using System;

using System.Linq;

public class Program {

public static int[] Puzzle(int n) {

return Enumerable.Range(0, n).Select(x => x * n).ToArray();

}

}

02.04

using System;

public class Program {

public static int Puzzle(int[] v) {

int sum = 0;

foreach (int e in v) {

sum += e;

}

return sum;

}

}

02.05

using System;

public class Program {

public static int Puzzle(int n) {

return (n-1)*(n)*(2*n-1)/6;

}

}

02.06

using System;

using System.Linq;

public class Program {

public static int Puzzle(string s) {

return s.Length - s.Replace("a", "").Length;

}

}

02.07

using System;

using System.Linq;

public class Program {

public static int Puzzle(string s, char x) {

return s.Length - s.Replace(""+x, "").Length;

}

}

chapter 03

03.01

using System;

public class Program {

public static int Puzzle(int a, int x) {

int b = 1;

for (; x>0; x/=2, a*=a)

if (x % 2 == 1) b *= a;

return b;

}

}

03.02

using System;

public class Program {

public static int Puzzle(int i) {

return (i == 0)? 1: i * Puzzle(i-1);

}

}

03.03

using System;

public class Program {

public static int Puzzle(int lowerBound, int upperBound) {

int product = 1;

for (int i = lowerBound; i <= upperBound; ++i) {

product *= i;

}

return product;

}

}

03.04

using System;

public class Program {

public static int Puzzle(int n) {

return (n <= 0)? 0: (n+1) / 2 * ((n + 1) / 2 - 1);

}

}

03.05

using System;

public class Program {

public static int Puzzle(int n) {

return n*(n+1)*(n+2)/6;

}

}

03.06

using System;

using System.Linq;

public class Program {

public static string Puzzle(string word) {

return string.Join(" ", (new string(‘_‘, word.Length)).AsEnumerable());;

}

}

03.07

using System;

using System.Linq;

public class Program {

public static string Puzzle(string s) {

return string.Join("",

s.Select(

c => (char)((c > 117)? (c - 21): (c + 5))

)

);

}

}

03.08

using System;

public class Program {

public static int Puzzle(int x) {

string s = "";

s += x;

return s.Length;

}

}

chapter 04

04.01

using System;

public class Program {

public static bool Puzzle(bool x, bool y) {

return x || y;

}

}

04.02

using System;

public class Program {

public static bool Puzzle(bool x, bool y) {

return x && y;

}

}

04.03

using System;

public class Program {

public static bool Puzzle(int x) {

return x<50;

}

}

04.04

using System;

public class Program {

public static bool Puzzle(int x, int y) {

return x<y;

}

}

04.05

using System;

public class Program {

public static int Puzzle(int i) {

return (i == 0)? 0: Math.Abs(i)/i;

}

}

04.06

using System;

public class Program {

public static bool Puzzle(int i, int j) {

return false;

}

}

04.07

using System;

public class Program {

public static int Puzzle(int i) {

return (i < 100)? 2: 3;

}

}

04.08

using System;

public class Program {

public static string Puzzle(int i) {

return (i % 2 == 0)? "even": "odd";

}

}

04.09

using System;

public class Program {

public static string Puzzle(int i) {

return ((i % 5 == 0)? "": "not a ") + "multiple of 5";

}

}

04.10

using System;

public class Program {

public static string Puzzle(int i, int x) {

return ((i % x == 0)? "": "not a ") + ("multiple of " + x);

}

}

04.11

using System;

public class Program {

public static string Puzzle(int i, int j, int k) {

if (i / (double)j == j / (double)k && (i!=j)) return "yes!";

return "no";;

}

}

04.12

using System;

public class Program {

public static int Puzzle(int i) {

if (i < 8) return 0;

if (i < 15) return 7;

return 21;

}

}

chapter 05

05.01

using System;

public class Program {

public static string Puzzle(string s) {

if(s.Length<4){

return "short";

}else if(s.Length<8){

return "average";

}else if(s.Length<15){

return "long";

}else{

return "super long";

}

}

}

05.02

using System;

public class Program {

public static string Puzzle(int i) {

if(i>1000&&i<10000){

int test=i%10;i=i/10;

while(i>0&&test==i%10){

test=i%10;

i=i/10;

}

}

if(i==0){

return "fancy year";

}else{

return "not a fancy year";

}

}

}

05.03

using System;

public class Program {

public static bool Puzzle(int a, int b, int c) {

return (Math.Pow(Math.Min(a,b),2)==(Math.Max(a,b)+c)*(Math.Abs(c-Math.Max(a,b))))?true:false;

}

}

05.04

using System;

public class Program {

public static int Puzzle(int x, int y) {

return Math.Abs(x)+Math.Abs(y);

}

}

05.05

using System;

public class Program {

static int gcd(int m, int n)

  {

if(m%n!=0){

return gcd(n,m%n);

}else{

return n;

}

  }

public static bool Puzzle(int i, int j) {

if(gcd(i,j)!=1){

return true;

}

else{

return false;

}

}

}

微软Code Hunt答案(00-05)——沉迷娱乐的我

时间: 2024-12-01 17:19:47

微软Code Hunt答案(00-05)——沉迷娱乐的我的相关文章

code hunt题解(1)

code hunt 这个网站类似于learn codecademyd,都是通过闯关,给你一些碎片化的程序片段,然后你需要完成它需要你返回的结果.但是怎么说呢,code hunt的题目更加无厘头一点,因为他只会给你一些你需要返回的数据,而并没有明确说明如何得到.所以它更类似游戏(有人说这是微软的网游,其实真的很不错,安利一下).当然这个网站也有C#的学习(貌似网上有大牛看书刷这个就进了编程之美C#复赛,哈哈哈想想那些学C#的还天天打游戏的人,多亏我来hit了)逃.恩,注册一个微软账号或者faceb

Bentley STAAD Planwin 14.00.05.00 1CD建筑结构设计

Bentley STAAD Planwin 14.00.05.00 1CD建筑结构设计STAAD.Pro 是结构工程专业人员的最佳选择,可通过其灵活的建模环境.高级的功能和流畅的数据协同进行涵洞.隧道.桥 梁.石化工厂.桥墩等几乎任何设施的混凝土结构.木结构.钢结构.铝结构和冷弯型钢结构设计.STAAD.Pro集成了 STAAD.Foundation 设计模块. 1.Bentley STAAD Planwin 14.00.05.00 1CD建筑结构设计Bentley STAAD Planwin

全面3D钢结构桥梁和评估应用LEAP Bridge Steel CONNECT Edition 16.01.00.05 1CD

全面3D钢结构桥梁和评估应用LEAP Bridge Steel CONNECT Edition 16.01.00.05 1CD LEAP Bridge Steel CONNECT Edition V16 Update 1 (16.01.00.05) 包括了许多增强的功能,并修复了已知的老版本存在的一些错误.增强功能包括两个新增加的成员定义命令:一个自动生成主梁腹板和翼缘板和其他执行对翼缘板优化设计(主梁腹板的优化设计将包括在下一版本).另一个重要的改进增加了非棱柱截面检查,用于设计规范检查.LE

雷霆战机 版本:1.00.05

内容介绍 雷霆战机是腾讯独家代理,北京爱乐游倾力打造的国内首款星座推图射击大作数十种装备,打造专属战机;无尽挑战领略太空激战,星际争霸驰骋十二星座!安卓手机软件下载就去优亿市场! 攻略: 雷霆战机游戏出来有一段时间了,玩了这么久,略有心得,这里写出来和大家分享一下;你又有什么样的心得呢?大家一起来交流交流吧! 关于飞机的看法: 不是千元党不要碰异形!憋说异形多牛比,你好友全紫你还一星蓝的时候你就哭吧,有争议的应该只有激光和贯穿.很多大神推荐贯穿,但贯穿确实伤害奇低,只是爆率比激光大些.三星紫需要

code::blocks(版本10.05) 配置opencv2.4.3

(1)首先下载opencv2.4.3, 解压缩到D:下: (2)配置code::blocks, 具体操作如下: 第一步, 配置compiler, 操作步骤为Settings  -> Compiler and debugger 这样出现如下图: 第二步:add link(添加链接): 接下来, 切换到opencv 的解压目录目录:  D:\opencv\build\include 配置完Compiler之后, 在配置linker: 同理如下图: 第三步, 配置linker settings (也就

Free download Vediamo software Vediamo 5.00.05

This post collect all of Foxwell GT80 / GT80 Plus questions and engineer answers from foxwellshop customers, hope it enlighten others who are interested in this tool. BTW, Foxwell GT80 and GT80 Plus share the same function and vehicle coverage, the o

CLOC(Count Lines Of Code)代码统计工具

cloc 是一个 perl 脚本,它可以统计很多种编程语言的代码文件中的空行.注释以及实际的代码行数. 相关网站: http://cloc.sourceforge.net/ http://sourceforge.jp/projects/sfnet_cloc/releases/ 安装 环境 windows 7 + Vmware Player 6.0 + fedora 18(linux 3.6.10) + gcc 4.7.2 Linux环境下: [[email protected] ~]# yum

[LeetCode][JavaScript]Gray Code

Gray Code The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray code. A gray code sequence must begin

2015微软创新杯Imaginecup大赛报名进行中(报名截止2014年12月31日23:59)

CSDN高校俱乐部与微软官方合作,2015微软创新杯大赛中国区官网落户CSDN高校俱乐部:http://student.csdn.net/mcs/imaginecup2015 在微软官方设置创新杯中国区奖项之外,CSDN高校俱乐部每个竞赛项目特设一等奖.二等奖.三等奖及纪念奖若干名. CSDN高校俱乐部特别奖(获奖者需在高校俱乐部进行过报名备案):详情-> 1. 一等奖(三支团队): 每个竞赛项目一等奖一名,每支团队获得奖金2,000元人民币,团队成员每人尊享2015 CSDN VIP年卡会员: