using System;
internal class Program {
private static void Main() {
Console.WriteLine("Введите минимум для счетчика");
var min = int.Parse(Console.ReadLine() ?? throw new ());
Console.WriteLine("Введите максимум для счетчика");
var max = int.Parse(Console.ReadLine() ?? throw new ());
Console.WriteLine("Введите значение для счетчика");
var v = int.Parse(Console.ReadLine() ?? throw new ());
var counter = new Counter(max, min, v);
Console.WriteLine("Введите + для увеличение и - для уменьшения, иное для выхода");
do {
var c = Console.ReadKey();
if (c.KeyChar == '+') counter.Increase();
else if (c.KeyChar == '-') counter.Decrease();
else break;
Console.WriteLine($" => {counter.Value}");
} while (true);
Console.ReadKey();
}
}
public class Counter {
public readonly int Maximum;
public readonly int Minimum;
public int Value { private set; get; }
public Counter(int maximum, int minimum, int counter) {
this.Maximum = maximum;
this.Minimum = minimum;
counter = Math.Min(this.Maximum, counter);
counter = Math.Max(this.Minimum, counter);
this.Value = counter;
}
private Counter() {
this.Maximum = 10;
this.Minimum = 0;
this.Value = 5;
}
public void Increase() {
var value = this.Value + 1;
if (value > this.Maximum || value < this.Minimum)
return;
this.Value++;
}
public void Decrease() {
var value = this.Value - 1;
if (value > this.Maximum || value < this.Minimum)
return;
this.Value--;
}
}
// PascalABC.NET 3.0, сборка 1073
const
sb='bcdfgjklmnpqrstvwxz';
s='Computer programming is a process of computer programs creation';
var
i,n:integer;
s1,sn,t:string;
begin
i:=1;
while s[i]<>' ' do Inc(i);
s1:=Copy(s,1,i-1);
n:=Length(s); i:=n;
while s[i]<>' ' do Dec(i);
sn:=Copy(s,i+1,n-i);
t:='';
for i:=1 to Length(s1) do
if Pos(s1[i],sb)>0 then t:=t+s1[i];
s1:=t;
t:='';
for i:=1 to Length(sn) do
if Pos(sn[i],sb)>0 then t:=t+sn[i];
sn:=t;
t:='';
for i:=1 to Length(s1) do
if Pos(s1[i],sn)>0 then
if Pos(s1[i],t)=0 then t:=t+s1[i];
for i:=1 to Length(t) do Write(t[i],' ');
Writeln
end.
Тестовый прогон:
t r
2. "Нормальное" решение
// PascalABC.NET 3.0, сборка 1073
const
sb='bcdfgjklmnpqrstvwxz';
s='Computer programming is a process of computer programs creation';
begin
var a:=s.ToWords(' ');
a[0].Intersect(a[a.Length-1]).Where(x->Pos(x,sb)>0).Println(',')
end.
Тестовый прогон:
t,r