# Код на ruby 2.2.3p173 def zadanie(numbers) p "***" s = 0 numbers.each{|n| s += n} p [s, numbers] numbers = numbers.sort
while s % 3 != 0 do numbers.each{|n| if (s-n) % 3 == 0 s -= n numbers.delete(n) p n break end } if s % 3 != 0 n = numbers.min s -= n numbers.delete(n) p n end p numbers end
return numbers.reverse end
# # Примеры применения p zadanie([7, 2, 3, 1, 5, 9, 4, 7])
def zadanie(numbers)
p "***"
s = 0
numbers.each{|n| s += n}
p [s, numbers]
numbers = numbers.sort
while s % 3 != 0 do
numbers.each{|n|
if (s-n) % 3 == 0
s -= n
numbers.delete(n)
p n
break
end
}
if s % 3 != 0
n = numbers.min
s -= n
numbers.delete(n)
p n
end
p numbers
end
return numbers.reverse
end
# # Примеры применения
p zadanie([7, 2, 3, 1, 5, 9, 4, 7])
Вывод
[38, [7, 2, 3, 1, 5, 9, 4, 7]]
2
[1, 3, 4, 5, 7, 7, 9]
[9, 7, 7, 5, 4, 3, 1]
ответ 9775431
using namespace std;
int main()
{
int N,A,M;
double S = 0;
cout << "N = ", cin >> N, cout << "\n";
cout << "Vvedite N chisel:" << endl;
cin >> A;
M = A;
S+=A;
for(int i=2; i<=N; i++)
{
cin >> A;
if (A<M) M = A;
S+= A;
}
cout << "Srednee arifm. = " << S/N << "\n";
cout << "Min = " << M << "\n";
system("pause");
return 0;
}