8192 / 8 = 1024 байт - переводим в байты
1024 / 1024 = 1 килобайт - переводим в килобайты
#include <iostream>
using namespace std;
/*
* Сумма элементов массива
* [ 1, 2, 3] => 6
* [-5, 8, 2] => 5
*/
int arraySum(int a[], int s)
{
int ret = 0;
for (int i = 0; i < s; i++) {
ret += a[i];
}
return ret;
}
/*
* Определение, каких чисел больше в массиве.
* [-1, 2, 3] => "Положительных"
* [ 1, -2, -3] => "Отрицательных"
*/
const char* plusMinGreater(int a[], int s)
{
int plus = 0, minus = 0;
for (int i = 0; i < s; i++) {
if (a[i] > 0) plus++;
if (a[i] < 0) minus++;
}
return (plus > minus ?
"Положительных чисел больше" :
(plus < minus ?
"Отрицательных чисел больше" :
"Положителных и отрицательных поровну"));
}
/*
* Разница между максимальным и минимальным элементами.
* [5, 3, 2] => 5 - 2 = 3
*/
int maxMinDiff(int a[], int s)
{
int min = a[0], max = a[0];
for (int i = 1; i < s; i++) {
if (a[i] > max) max = a[i];
if (a[i] < min) min = a[i];
}
return max - min;
}
int main()
{
int n;
cout << "n = ";
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cout << "Число " << i << ": ";
cin >> a[i];
}
cout << plusMinGreater(a, n) << endl
<< "Сумма: " << arraySum(a, n) << endl
<< "Разница максимального и минимального элементов: "
<< maxMinDiff(a, n) << endl;
return 0;
}
===== PascalABC.NET =====
begin
var n := ReadInteger('n =');
var m := Range(1, n).Average;
if m > 17 then
Print(m - 5)
else
Range(1, n).Aggregate(BigInteger.One, (p, q) -> p * q).Print
end.
#include <bits/stdc++.h>
using namespace std;
int a[10];
int main()
{
string s;
cin >> s;
for (int i = 0; i < s.length(); ++i)
a[s[i] - '0']++;
for (int i = 0; i < 10; ++i)
if (a[i])
{
cout << a[i];
return 0;
}
}
# Код на ruby 2.2.3p173
(9999).downto(1000) {|i|
s = i.to_s()
s = s[0..2] + s.reverse
n = s.to_i
next if not s.include?('7')
next if not s.include?('4')
sum = 0
while n > 0 do
sum += n % 10
n = n / 10
end
next if sum != 39
p s
break;
}
Ответ 9437349