if (mistake) { printf("Invalid code.\n"); return -1; } }
printf("Fixed code: %s\n", input); for (i = 0; i < len; i++) if (i + 1 == b) b <<= 1; else info[info_pos++] = input; info[info_pos] = '\0'; printf("Informational string: %s\n", info); return 0; }
//PascalABC.NET (версия 3.1, сборка 1196 от 09.03.2016) function Transpose(a: array[,] of integer): array[,] of integer; //Поворот на 90гр по часовой стрелке begin var m := Length(a, 0); var n := Length(a, 1); Result := new integer[n, m]; for var i := 0 to n-1 do begin for var j := 0 to m-1 do Result[i, j] := a[m-1-j, i]; end; end;
begin var n := ReadInteger('Введите n:'); //Заполнение матрицы NxN сл. числами и вывод на экран var a :=MatrixRandom(n, n); for var i:=0 to n-1 do begin for var j:=0 to n-1 do Print(a[i,j]); println; end; println;
Println('поворот влево на 90 гр'); var b := Transpose(a); b:=Transpose(b); b:=Transpose(b); for var i:=0 to n-1 do begin for var j:=0 to n-1 do Print(b[i,j]); println; end; println;
Println('поворот вправо на 90гр'); b := Transpose(a); for var i:=0 to n-1 do begin for var j:=0 to n-1 do Print(b[i,j]); println; end; println;
Println('поворот на 180 гр'); b := Transpose(a); b := Transpose(b); for var i:=0 to n-1 do begin for var j:=0 to n-1 do Print(b[i,j]); println; end; end.
#include <stdlib.h>
char input[1024];
int len;
int find_mistake()
{
int i, mistake = 0;
for (i = 0; i < len; i ++)
if (input == '1')
mistake ^= i + 1;
return mistake;
}
int main()
{
int i, mistake = 0;
char info[1024];
int info_pos = 0;
int b = 1;
printf("Enter code: ");
scanf("%s", input);
len = strlen(input);
for (i = 0; i < len; i++)
if (input != '0' && input != '1')
{
printf("Invalid code.\n");
return -1;
}
mistake = find_mistake();
if (mistake)
{
input[mistake - 1] ^= '0' ^ '1';
mistake = find_mistake();
if (mistake)
{
printf("Invalid code.\n");
return -1;
}
}
printf("Fixed code: %s\n", input);
for (i = 0; i < len; i++)
if (i + 1 == b)
b <<= 1;
else
info[info_pos++] = input;
info[info_pos] = '\0';
printf("Informational string: %s\n", info);
return 0;
}
function
Transpose(a: array[,] of integer): array[,] of integer;
//Поворот на 90гр по часовой стрелке
begin
var m := Length(a, 0);
var n := Length(a, 1);
Result := new integer[n, m];
for var i := 0 to n-1 do begin
for var j := 0 to m-1 do
Result[i, j] := a[m-1-j, i];
end;
end;
begin
var n := ReadInteger('Введите n:');
//Заполнение матрицы NxN сл. числами и вывод на экран
var a :=MatrixRandom(n, n);
for var i:=0 to n-1 do begin
for var j:=0 to n-1 do
Print(a[i,j]);
println;
end;
println;
Println('поворот влево на 90 гр');
var b := Transpose(a);
b:=Transpose(b);
b:=Transpose(b);
for var i:=0 to n-1 do begin
for var j:=0 to n-1 do
Print(b[i,j]);
println;
end;
println;
Println('поворот вправо на 90гр');
b := Transpose(a);
for var i:=0 to n-1 do begin
for var j:=0 to n-1 do
Print(b[i,j]);
println;
end;
println;
Println('поворот на 180 гр');
b := Transpose(a);
b := Transpose(b);
for var i:=0 to n-1 do begin
for var j:=0 to n-1 do
Print(b[i,j]);
println;
end;
end.