Advertisement
savrasov

strr

Jan 8th, 2017
3,343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program strr;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   SysUtils;
  7.  
  8. var
  9.   a, b: array [1..3000] of string;
  10.   s: string;
  11.   boo: array [1..3000] of boolean;
  12.   i, len, f: integer;
  13.  
  14. function fu(c: char): integer;
  15. begin
  16.   if (ord(c) > 96) then fu := ord(c) - 97
  17.   else fu := (ord(c) - 65) + 26;
  18. end;
  19.  
  20. function tobin(a: integer): string;
  21. var
  22.   s: string;
  23. begin
  24.   while (a <> 0) do
  25.   begin
  26.     s := inttostr(a mod 2) + s;
  27.     a := a div 2;
  28.   end;
  29.   while (length(s) < 5) do s := '0' + s;
  30.   tobin := s;
  31. end;
  32.  
  33. function inv(s: string): string;
  34. var
  35.   i: integer;
  36. begin
  37.   for i := 1 to length(s) do
  38.     if (s[i] = '0') then s[i] := '1'
  39.     else s[i] := '0';
  40.   inv := s;
  41. end;
  42.  
  43. procedure no();
  44. begin
  45.   writeln('Ahmat made a mistake');
  46.   halt(0);
  47. end;
  48.  
  49. begin
  50.   readln(s);
  51.   len := length(s);
  52.   for i := 1 to length(s) do a[i] := tobin(fu(s[i]));
  53.   readln(s);
  54.   if (length(s) <> len) then no;
  55.   f := 0;
  56.   for i := 1 to len do b[i] := tobin(fu(s[i]));
  57.   for i := 1 to len do
  58.     if (a[i] = b[i]) then boo[i] := false
  59.     else if (a[i] = inv(b[i])) then boo[i] := true
  60.     else no;
  61.   i := 1;
  62.   while (i <= len) do
  63.   begin
  64.     if (boo[i]) then
  65.     begin
  66.       while (boo[i]) do inc(i);
  67.       inc(f);
  68.     end;
  69.     inc(i);
  70.   end;
  71.   writeln('Ahmat rights');
  72.   writeln(f);
  73. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement