首页 > 代码库 > 微软Code Hunt答案(00-05)——沉迷娱乐的我
微软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;
}
}
}