using System;
namespace ConsoleApp18
{
class Program
static void Main(string[] args)
string s = Console.ReadLine();
int n = int.Parse(s.Split(' ')[0]), m = int.Parse(s.Split(' ')[1]), sum = 0;
int[,] a = new int[n,m];
for (int i = 0; i < n; i++)
s = Console.ReadLine();
for (int j = 0; j < m; j++)
a[i, j] = int.Parse(s.Split(' ')[j]);
sum += a[i, j];
}
Console.WriteLine(sum);
Console.ReadKey();
Объяснение:
===== PascalABC.NET =====
function S(a: array[,] of integer) :=
a.Cols.Where(p -> p.All(q -> q >= 0)).SelectMany(p -> p).Sum;
function M(a: array[,] of integer): integer;
begin
var n := a.RowCount;
Result := integer.MaxValue;
var s: integer;
for var i := 0 to n - 2 do
s := 0;
for var j := 0 to i do
s += Abs(a[i - j, j]);
if s < Result then
Result := s
end;
for var j := 1 to n - 1 do
for var i := n - 1 downto j do
s += Abs(a[i, n - i + j - 1]);
end
var n := ReadInteger('n =');
var a := MatrRandom(n, n, -10, 30);
a.Println;
S(a).Println;
M(a).Println;
end.
using System;
namespace ConsoleApp18
{
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
int n = int.Parse(s.Split(' ')[0]), m = int.Parse(s.Split(' ')[1]), sum = 0;
int[,] a = new int[n,m];
for (int i = 0; i < n; i++)
{
s = Console.ReadLine();
for (int j = 0; j < m; j++)
{
a[i, j] = int.Parse(s.Split(' ')[j]);
sum += a[i, j];
}
}
Console.WriteLine(sum);
Console.ReadKey();
}
}
}
Объяснение:
===== PascalABC.NET =====
function S(a: array[,] of integer) :=
a.Cols.Where(p -> p.All(q -> q >= 0)).SelectMany(p -> p).Sum;
function M(a: array[,] of integer): integer;
begin
var n := a.RowCount;
Result := integer.MaxValue;
var s: integer;
for var i := 0 to n - 2 do
begin
s := 0;
for var j := 0 to i do
s += Abs(a[i - j, j]);
if s < Result then
Result := s
end;
for var j := 1 to n - 1 do
begin
s := 0;
for var i := n - 1 downto j do
s += Abs(a[i, n - i + j - 1]);
if s < Result then
Result := s
end
end;
begin
var n := ReadInteger('n =');
var a := MatrRandom(n, n, -10, 30);
a.Println;
S(a).Println;
M(a).Println;
end.