function [Pre Post] = AdjacentLetterCounts(STR,k)
%[Pre Post] = AdjacentLetterCounts(STR,k)
%Inputs:  STR = a string of upper case ciphertext w/ (possible) spaces, and
%k = a number between 0 and 25 giving corresponding to a ciphertext letter.
%Output: Two length 26 vectors Pre and Post which give, for the ciphertext
%letter corr. to k, the number of times each of the 26 letters occurs directly
%before (Pre) and directly after (Post) this letter corr. to k in a word.  So if the
%letter occurs at the beginning/end of a word the last letter of the
%previous word/first letter of the subsequent word makes no contributions
%to this letter.

Pre = zeros(1,27); Post = Pre;

Vec = UCTextWithSpaces2Int(STR);
if Vec(1) == k, Post(Vec(2)+1) = Post(Vec(2)+1) + 1; end
for j = 2:length(Vec)-1
        if Vec(j) == k;
            Pre(Vec(j-1)+1)=Pre(Vec(j-1)+1)+1;
            Post(Vec(j+1)+1)=Post(Vec(j+1)+1)+1;
        end
end
if Vec(length(STR)) == k, Pre(Vec(length(STR)-1)+1) = Pre(Vec(length(STR)-1)+1) + 1; end

Pre(27) = []; Post(27) = [];    
            
fprintf('   Letter counts for the letter %s            \r', char(k+65))
fprintf('============================================================\r')
fprintf('Before      After   Before OR After\r')
for j=0:25
    if Pre(j+1)<10
   fprintf('   %d    %s     %d        %d      \r', Pre(j+1), char(65+j), Post(j+1), Pre(j+1)+Post(j+1));
    else
    fprintf('  %d    %s     %d        %d      \r', Pre(j+1), char(65+j), Post(j+1), Pre(j+1)+Post(j+1));
    end
end
fprintf('The letter %s does not appear before/after %d ciphertext letters.\r', char(65+k), 26 - nnz(Pre+Post))
