===== 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.
#include <iostream>
using namespace std;
int main () {
int n;
cin >> n;
if (n==0) {
cout << "0 0" << endl << 1 << endl << 1 << endl;
return 0;
}
int mx=0; int mn=10; int mxi=10; int mnk=0; int ind=0;
while (n>0) {
int c=n%10;
n/=10;
if (c>=mx) {
mx=c;
mxi=ind;
if (c<mn) {
mn=c;
mnk=1;
} else if (c==mn) {
++mnk;
++ind;
cout << mx << " " << mn << endl << (ind - mxi) << endl << mnk << endl;
Объяснение:
===== 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.
#include <iostream>
using namespace std;
int main () {
int n;
cin >> n;
if (n==0) {
cout << "0 0" << endl << 1 << endl << 1 << endl;
return 0;
}
int mx=0; int mn=10; int mxi=10; int mnk=0; int ind=0;
while (n>0) {
int c=n%10;
n/=10;
if (c>=mx) {
mx=c;
mxi=ind;
}
if (c<mn) {
mn=c;
mnk=1;
} else if (c==mn) {
++mnk;
++ind;
}
}
cout << mx << " " << mn << endl << (ind - mxi) << endl << mnk << endl;
return 0;
}
Объяснение: