微软编码游戏 https://www.codehunt.com
Code Hunt 10.01
public class Program {
public static int Puzzle(int[][] list, int i, int j) {
return list[i][j];
}
}
Code Hunt 10.02
public class Program {
public static int[][] Puzzle() {
int[][] result = new int[5][];
for (int i = 0; i < result.length; i++) {
result[i] = new int[5];
}
return result;
}
}
Code Hunt 10.03
public class Program {
public static int[][] Puzzle(int length, int x) {
int[][] result = new int[length][];
for (int i = 0; i < result.length; i++) {
result[i] = new int[length];
for (int j = 0; j < length; j++)
result[i][j] = x;
}
return result;
}
}
Code Hunt 10.04
public class Program {
public static int[][] Puzzle(int[][] input) {
int[][] result = new int[input.length][];
for (int i = 0; i < input.length; i++) {
result[i] = new int[input[i].length];
for (int j = 0; j < input[i].length; j++) {
result[i][j] = input[i][j] * 2;
}
}
return result;
}
}
Code Hunt 10.05
public class Program {
public static int Puzzle(int[][] input, int i) {
int result = 0;
for (int j = 0; j < input.length; j++) {
for (int k = 0; k < input[j].length; k++) {
if (i == input[j][k]) {
result++;
}
}
}
return result;
}
}
Code Hunt 10.06
public class Program {
public static int Puzzle(int[][] input) {
int result = 0;
for (int i = 0; i < input.length; i++) {
for (int j = 0; j < input[i].length; j++) {
if (input[i][j] > result) {
result = input[i][j];
}
}
}
return result;
}
}
Code Hunt 10.07
public class Program {
public static int[] Puzzle(int[][] input) {
int maxIndex = 0;
int maxSum = 0;
for (int i = 0; i < input.length; i++) {
int sum = 0;
for (int j = 0; j < input[i].length; j++) {
sum += input[i][j];
}
if (sum > maxSum) {
maxIndex = i;
maxSum = sum;
}
}
return input[maxIndex];
}
}
Code Hunt 10.08
public class Program {
public static int Puzzle(int[][] input) {
int result = 0;
for (int j = 0; j < input.length; j++) {
int sum = 0;
for (int i = 0; i < input.length; i++) {
sum += input[i][j];
}
if (sum > result) {
result = sum;
}
}
return result;
}
}