Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program New;
- function KeyDistance(CharA, CharB: Char): Extended;
- var
- kbd:Array of TStrArray;
- i,j,l:Integer;
- A,B:TPoint;
- CharASet,CharBSet:Boolean;
- begin
- SetLength(kbd, 4);
- SetLength(kbd[0], 12);
- kbd[0][0] := '1!';
- kbd[0][1] := '2@';
- kbd[0][2] := '3#';
- kbd[0][3] := '4$';
- kbd[0][4] := '5%';
- kbd[0][5] := '6^';
- kbd[0][6] := '7&';
- kbd[0][7] := '8*';
- kbd[0][8] := '9(';
- kbd[0][9] := '0)';
- kbd[0][10] := '-_';
- kbd[0][11] := '+=';
- SetLength(kbd[1], 12);
- kbd[1][0] := 'qQ';
- kbd[1][1] := 'wW';
- kbd[1][2] := 'eE';
- kbd[1][3] := 'rR';
- kbd[1][4] := 'tT';
- kbd[1][4] := 'yY';
- kbd[1][5] := 'uU';
- kbd[1][6] := 'iI';
- kbd[1][7] := 'oO';
- kbd[1][8] := 'pP';
- kbd[1][9] := '{[';
- kbd[1][10] := '}]';
- kbd[1][11] := '|\';
- SetLength(kbd[2], 11);
- kbd[2][0] := 'aA';
- kbd[2][1] := 'sS';
- kbd[2][2] := 'dD';
- kbd[2][3] := 'fF';
- kbd[2][4] := 'gG';
- kbd[2][5] := 'hH';
- kbd[2][6] := 'jJ';
- kbd[2][7] := 'kK';
- kbd[2][8] := 'lL';
- kbd[2][9] := ':;';
- kbd[2][10] := '"''';
- SetLength(kbd[3], 11);
- kbd[3][0] := '~';
- kbd[3][1] := 'zZ';
- kbd[3][2] := 'xX';
- kbd[3][3] := 'cC';
- kbd[3][4] := 'vV';
- kbd[3][5] := 'bB';
- kbd[3][6] := 'nN';
- kbd[3][7] := 'mM';
- kbd[3][8] := ',<';
- kbd[3][9] := '.>';
- kbd[3][10] := '?/';
- A.x := 2; //centralize unknown chars | to not muss up measuring.
- A.y := 5;
- B.x := 2;
- B.y := 5;
- for l:=0 to High(kbd) do
- for i:=0 to High(kbd[l]) do
- for j:=1 to Length(kbd[l][i]) do
- begin
- if (kbd[l][i][j] = charA) and not(CharASet) then
- begin
- A.x := l;
- A.y := i+j-1;
- CharASet := True;
- end;
- if (kbd[l][i][j] = charB) and not(CharBSet) then
- begin
- B.x := l;
- B.y := i+j-1;
- CharBSet := True;
- end;
- if CharBSet and CharASet then Break;
- end;
- Result := Sqrt(Sqr(A.x-B.x) + Sqr(A.y-B.y));
- end;
- function StrQwertyDist(StrA, StrB:String): Extended;
- var
- i,L,lenA,lenB:Integer;
- Undefined: Char;
- begin
- Undefined := '|';
- LenA := Length(StrA);
- LenB := Length(StrB);
- L := Max(LenA, LenB);
- for i:=1 to L do
- begin
- if (i > lenA) then
- begin
- Result := Result + KeyDistance(Undefined, StrB[i]);
- end else if (i > lenB) then
- begin
- Result := Result + KeyDistance(StrA[i], Undefined);
- end else
- Result := Result + KeyDistance(StrA[i], StrB[i]);
- end;
- end;
- begin
- WriteLn(StrQwertyDist('Hello world', 'Hwllp workf'));
- WriteLn(StrQwertyDist('This is a long string', 'thix ia a lpng strkng'));
- WriteLn(StrQwertyDist('Testing someting else here', 'what in the world is going on?'));
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement