Delete the words satisfying the alphabet



  • There are two files: input.txt and output.txt

    Let's say the input.txt contains:

    Аа АА БЕВ бк бев бк
    Абев
    АААа
    бк
    бкбк
    бкбкбк
    

    Then output.txt will contain:

    АААа
    бк
    бкбк
    

    The first line in input.txt is alphabet, the words below are indicated. The challenge is to test all words to the possibility of writing using alphabet, and the alphabet may be used in the drafting of the word as many times as its copies are in the alphabet. For example, the letter "bc" can be used once or twice, but not three. Please indicate the algorithm of this task (in Russian, C#, Pascal).

    Thank you very much for the clues. This assignment differs from the previous one with certain conditions which, in the end, significantly altered the programme code. Decided a possible solution based on the response of the previous such mission:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Text.RegularExpressions;
    

    namespace Dictionary
    {
    class Program
    {
    static void Main(string[] args)
    {
    var input = File.ReadAllLines("input.txt", Encoding.UTF8);
    var alphabet = input[0].Split(' ');
    var outList = new List<string>();

            for (var i = 1; i &lt; input.Length; i++)
            {
                var word = input[i];
    
                foreach (var el in alphabet)
                    word = new Regex(el).Replace(word, " ", 1);
    
                if (String.IsNullOrWhiteSpace(word)) outList.Add(input[i]);                    
            }
    
            File.WriteAllLines("output.txt", outList, Encoding.UTF8);
        }
    }
    

    }



  • Put the alphabet in the line. You take the word, and a copy of the alphabet line. Take the letters from the cycle, search the line of the alphabet, remove the letter from the alphabet. If there's no further letter in the alphabet, the word is not appropriate. And so on with all the words.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2