C++ expert to solve a mathmatical problem

Job ID: 32205944

Budget: $30 – $250 USD

We have a C++ program that reads PDFs, extract each line and read the letters (total 36 letters in Albanian). we want to have specific count for each letter, so for example, 100 'A', 90 'B', 45 'C' etc. We then want to keep only sentences which result in the closest number of letters which is defined. See screenshot attached to understand the logic.
We have an algorithm but it's not working proparly. We need someone to help us get the best result with 90%-95% deviation. This is a small project.