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

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

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

                转载请著明:http://blog.csdn.net/grublinux/article/details/26380131

     微软Code Hunt答案(00-05)——沉迷娱乐的我_第1张图片

注:澄清一些误会,下面的答案不是全部三星。有一些是还有优化余地的,为了免得误会我把能优化的题目用红色标注。然后如果大家提供了自己更加完美的答案,我会陆续更新上来,并且标注作者。谢谢大家,玩的开心!

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 * x).ToArray();
    }
}

02.04

using System;
using System.Linq;
public class Program {
    public static int Puzzle(int[] v) {
return (int)v.Sum(i => (long)i);
    }
}

Thanks For test4153(2 floor)

02.05

using System;
public class Program {
    public static int Puzzle(int n) {
        return (n-1)*(n)*(2*n-1)/6;
    }
}

return Enumerable.Range(0,n).Sum(i=>i*i);  Thanks For test4153(3 floor)

02.06

using System;
using System.Linq;
public class Program {
    public static int Puzzle(string s) {
        return s.Length - s.Replace("a", "").Length;
    }
}

return s.Sum(a=>a=='a'?1:0); Thanks For lgl404149074(5 floor)

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) {    
        return x<=0 ? 1 : a*Puzzle(a, x-1);
    }
}

Thanks For lgl404149074(5 floor)

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;
    }
}

return Enumerable.Range(lowerBound,upperBound-lowerBound+1).Aggregate(1,(sum,num)=>sum*num); 
Thanks For TrotylYu

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());

    }
}

return String.Join(" ",new String('_',word.Length).ToArray()); 

Thanks For TrotylYu

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;
    }
}

return x.ToString().Length;

Thanks For TrotylYu

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     }
}

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;
    }
}

return i>14?21:((i-1)/7)*7;  Thanks For  brown_cat(11 floor)

chapter 05

05.01

using System;
public class Program {
    public static string Puzzle(string s) {
int l = s.Length;
        return l<4?"short":l<8?"average":l<15?"long":"super long";
    }
}

Thanks For lgl404149074(5 floor)

05.02

using System;
public class Program {
    public static string Puzzle(int i) {
return (i % 1111 == 0) ? "fancy year" : "not a fancy year";  
    }
}

Thanks For lgl404149074(5 floor)

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 {
    public static bool Puzzle(int i, int j) {
       return i*i==j?true:false;
    }
}

Thanks For lgl404149074(5 floor)

你可能感兴趣的:(随笔)