class Program
{
static void Main(string[] args)
string src = " Qwy. ... Asdf.. Lkjdfs A.";
//string dest = ReplaceDots(src, '.', '…', 3);
string dest = ReplaceDots(src, '.', "...", 3);
Console.WriteLine("src:\t" + src);
Console.WriteLine("dest:\t" + dest);
Console.WriteLine();
Console.Write("Press any key for exit ...");
Console.ReadKey(true);
}
//private static string ReplaceDots(string src, char dotCh, char dots, int minDotsCount)
private static string ReplaceDots(string src, char dotCh, string dots, int minDotsCount)
StringBuilder dest = new StringBuilder();
int i = 0;
while (i < src.Length)
int dotsCount = 0;
while (i < src.Length && src[i] == dotCh)
dotsCount++;
i++;
if (dotsCount >= minDotsCount)
dest.Append(dots);
else if (dotsCount == 0)
dest.Append(src[i++]);
else
while (dotsCount-- > 0)
dest.Append(dotCh);
return dest.ToString(); ;
без использования всяких функций
Объяснение:
Pascal
var
a:array [1..12] of integer;
i, j, k:integer;
begin
randomize;
for i:=1 to 12 do
a[i]:=random(101)-50;
print(a);
writeln();
i:=1;
while i <= 12 do begin
for j:= i to 12 do
if a[j]<a[i] then begin
k:=a[j];
a[j]:=a[i];
a[i]:=k;
dec(i);
break;
end;
inc(i);
if a[3] mod 2 = 0 then
writeln(a[3], ' число четное')
writeln(a[3], ' число нечетное')
end.
class Program
{
static void Main(string[] args)
{
string src = " Qwy. ... Asdf.. Lkjdfs A.";
//string dest = ReplaceDots(src, '.', '…', 3);
string dest = ReplaceDots(src, '.', "...", 3);
Console.WriteLine("src:\t" + src);
Console.WriteLine("dest:\t" + dest);
Console.WriteLine();
Console.Write("Press any key for exit ...");
Console.ReadKey(true);
}
//private static string ReplaceDots(string src, char dotCh, char dots, int minDotsCount)
private static string ReplaceDots(string src, char dotCh, string dots, int minDotsCount)
{
StringBuilder dest = new StringBuilder();
int i = 0;
while (i < src.Length)
{
int dotsCount = 0;
while (i < src.Length && src[i] == dotCh)
{
dotsCount++;
i++;
}
if (dotsCount >= minDotsCount)
dest.Append(dots);
else if (dotsCount == 0)
dest.Append(src[i++]);
else
while (dotsCount-- > 0)
dest.Append(dotCh);
}
return dest.ToString(); ;
}
}
без использования всяких функций
Объяснение:
Pascal
var
a:array [1..12] of integer;
i, j, k:integer;
begin
randomize;
for i:=1 to 12 do
a[i]:=random(101)-50;
print(a);
writeln();
i:=1;
while i <= 12 do begin
for j:= i to 12 do
if a[j]<a[i] then begin
k:=a[j];
a[j]:=a[i];
a[i]:=k;
dec(i);
break;
end;
inc(i);
end;
print(a);
writeln();
if a[3] mod 2 = 0 then
writeln(a[3], ' число четное')
else
writeln(a[3], ' число нечетное')
end.