10.02 - int[][] r = {
new int [5], new int [5],
new int [5],
new int [5],
new int [5]
}
return r;
10.03 - int[][] r = new int [length][];
for(int i = 0; i < length; i++){
r[i] = new int [length];
for(int j = 0; j < length; j++){
r[i][j] = x;
}
}
return r;
10.04 - using System;
using System.Linq;
public class Program {
public static int[][] Puzzle(int[][] input) {
return input.Select(x => x.Select(y => y * 2).ToArray()).ToArray();
}
}
10.05 - int count = 0;
for(int a = 0; a < input.Length; a++){
for(int j = 0; j < input[a].Length; j++){
int n = input[a][j];
if (n == i)
count++;
}
}
return count;
10.06 - int count = 0;
for(int a = 0; a < input.Length; a++){
for(int j = 0; j < input[a].Length; j++){
int n = input[a][j];
if (n > count)
count = n;
}
}
return count;
10.07 - int[] r = new int [input[0].Length];
int maxAverage = 0;
for(int a = 0; a < input.Length; a++){
int average = 0;
for(int j = 0; j < input[a].Length; j++){
average += input[a][j];
}
if(average > maxAverage){
maxAverage = average;
r = input[a];
}
}
return r;
10.08 - I have no idea
10.08 (solution)
ReplyDeleteint max = 0;
for (int i = 0; i < input.length; i++) {
int sum = 0;
for (int j = 0; j < input[i].length; j++) sum += input[j][i];
max = Math.max(max, sum);
}
return max;