//C# 7.3, .NET Framework 4.7.2
namespace
{
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
private static Random r = new Random();
public static void Main()
{
var Xi = RandomArray(10, () => r.Next(-10, 10));
Xi.Println();
var notZeroCount = Xi.Count(item => item != 0);
var replaced = Xi.Replace(item => item != 0, 1);
notZeroCount.Println();
replaced.Println();
}
private static T[] RandomArray<T>(int count, Func<T> next)
{
var temp = new T[count];
for(var i = 0; i < count; i++)
temp[i] = next();
return temp;
}
}
public static class Extensions
{
public static IEnumerable<T> Replace<T>(this IEnumerable<T> source, Func<T, bool> selector, T newValue)
{
foreach (var item in source)
{
if (selector(item))
yield return newValue;
else
yield return item;
}
}
public static int Count<T>(this IEnumerable<T> source, Func<T, bool> selector)
{
var count = 0;
foreach (var item in source)
if (selector(item)) count++;
return count;
}
public static void Println<T>(this T[] source)
{
foreach (var item in source)
Console.Write(item.ToString() + " ");
}
public static void Println<T>(this IEnumerable<T> source)
{
source.ToArray().Println();
}
public static void Println<T>(this T source)
{
Console.WriteLine(source);
}
}
}
1) Два варианта (для ввода всех сразу или по одному):
1.1 По одному числу:
var
a,b:integer;
begin
readln(a);
b:=a;
readln(a);
if b>a then b:=a;
readln(a);
if b>a then b:=a;
writeln('min:',b);
end.
1.2 Все сразу:
var
a,b,c:integer;
begin
readln(a,b,c);
if a<=b then
if a<c then
writeln(a)
else writeln(c)
else
if b<c then
writeln(b)
else
writeln(c);
end.
2)
var
a:integer;
flag:boolean;
begin
flag:=false;
readln(a);
while a<>0 do
begin
if a mod 10 = 2 then
flag:=true;
a:=a div 10;
end;
writeln(flag);
end.