Var i, j, k : integer; a : array [0..9,0..9] of char; procedure U(i,j:integer); var c : char; begin c:=a[i,j]; a[i,j]:=' '; if (c='W')and(a[i+1,j]='B') then U(i+1,j); if (c='B')and(a[i+1,j]='W') then U(i+1,j); if (c='W')and(a[i-1,j]='B') then U(i-1,j); if (c='B')and(a[i-1,j]='W') then U(i-1,j); if (c='W')and(a[i,j+1]='B') then U(i,j+1); if (c='B')and(a[i,j+1]='W') then U(i,j+1); if (c='W')and(a[i,j-1]='B') then U(i,j-1); if (c='B')and(a[i,j-1]='W') then U(i,j-1); end; begin assign(input,'input.txt'); reset(input); assign(output,'output.txt'); rewrite(output); for i:=1 to 8 do begin for j:=1 to 8 do read(a[i,j]); readln end; for i:=1 to 8 do begin a[0,i]:=' '; a[9,i]:=' '; a[i,0]:=' '; a[i,9]:=' ' end; k:=0; for i:=1 to 8 do for j:=1 to 8 do if a[i,j]<>' ' then begin k:=k+1; U(i,j) end; write(k); close(output) end.
i, j, k : integer;
a : array [0..9,0..9] of char;
procedure U(i,j:integer);
var c : char;
begin
c:=a[i,j]; a[i,j]:=' ';
if (c='W')and(a[i+1,j]='B') then U(i+1,j);
if (c='B')and(a[i+1,j]='W') then U(i+1,j);
if (c='W')and(a[i-1,j]='B') then U(i-1,j);
if (c='B')and(a[i-1,j]='W') then U(i-1,j);
if (c='W')and(a[i,j+1]='B') then U(i,j+1);
if (c='B')and(a[i,j+1]='W') then U(i,j+1);
if (c='W')and(a[i,j-1]='B') then U(i,j-1);
if (c='B')and(a[i,j-1]='W') then U(i,j-1);
end;
begin
assign(input,'input.txt');
reset(input);
assign(output,'output.txt');
rewrite(output);
for i:=1 to 8 do begin for j:=1 to 8 do
read(a[i,j]);
readln
end;
for i:=1 to 8 do
begin
a[0,i]:=' '; a[9,i]:=' '; a[i,0]:=' '; a[i,9]:=' '
end;
k:=0;
for i:=1 to 8 do
for j:=1 to 8 do
if a[i,j]<>' ' then
begin
k:=k+1; U(i,j)
end;
write(k);
close(output)
end.
string a;
string b;
int count = 0;
int count2 = 0;
bool g = false;
bool g2 = false;
Console.WriteLine("Введите первую строку");
a = Convert.ToString(Console.ReadLine());
Console.WriteLine("Введите первую строку");
b = Convert.ToString(Console.ReadLine());
Console.WriteLine("Введите первый символ");
Макрой avatar
char first_symbol = Convert.ToChar(Console.ReadLine());
Console.WriteLine("Введите последний символ");
char second_symbol = Convert.ToChar(Console.ReadLine());
char[] separ = { ' ' };
string[] a1 = a.Split(separ);
string[] b1 = b.Split(separ);
Макрой avatar
for (int i = 0; i < a1.Length; i++)
if (a1[i].IndexOf(first_symbol) == 0 && a1[i].IndexOf(second_symbol) == a1[i].Length - 1)
{
Console.Write(a1[i]+";"); count++; g= true;
}
if (g)
{
Console.WriteLine(" В этой строке :" + count + " слов(о)");
}
Console.WriteLine();
Макрой avatar
for (int i = 0; i < b1.Length; i++)
if (b1[i].IndexOf(first_symbol) == 0 && b1[i].IndexOf(second_symbol) == b1[i].Length - 1)
{
Console.Write(b1[i]+";"); count2++; g2 = true;
}
if (g2)
{
Console.WriteLine(" В этой строке :" + count2 + " слов(о)");
}
Console.ReadLine();
Объяснение: