微软编码游戏 https://www.codehunt.com/
Code Hunt 02.01
public class Program {
public static int[] Puzzle(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = i;
}
return a;
}
}
Code Hunt 02.02
public class Program {
public static int[] Puzzle(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = n * i;
}
return a;
}
}
Code Hunt 02.03
public class Program {
public static int[] Puzzle(int n) {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = i * i;
}
return a;
}
}
Code Hunt 02.04
public class Program {
public static int Puzzle(int[] v) {
int result = 0;
for (int i = 0; i < v.length; i++) {
result = result + v[i];
}
return result;
}
}
Code Hunt 02.05
public class Program {
public static int Puzzle(int n) {
return (n - 1) * n * (2 * n - 1) / 6;
}
}
Code Hunt 02.06
public class Program {
public static int Puzzle(String s) {
return s.length() - s.replace("a", "").length();
}
}
Code Hunt 02.07
public class Program {
public static int Puzzle(String s, char x) {
return s.length() - s.replace(x + "", "").length();
}
}