4 comments on “Practice Room SRM 445 DIV 2, Problem 300

  1. not as efficient but looks a bit simpler, essentially inner joining substitute alpha / distinct list of the chars in message, back onto the message

    private string Enc(string message)
    {
    if (string.IsNullOrEmpty(message))
    {
    return “intput message cannot be empty”;
    }

    Dictionary subList = new Dictionary();
    List distinctSubChars = message.Distinct().ToList();
    int length = distinctSubChars.Count;

    Enumerable.Range(97, 26).ToList().ForEach(
    x => subList.Add(
    (char)x,
    (x – 97) > length -1 ? ’0′ : distinctSubChars[x - 97]
    ));

    var alphaCipher = (from c in message
    join subC in subList on c equals subC.Value
    where subC.Value != ’0′
    select subC.Key
    ).ToArray();

    return new string(alphaCipher);
    }

    • Hi dvr!
      Thank you for your new solution.. Do you use LINQ right?
      I am trying to run this code, and i couldn´t, i will check it.
      Are you sure that this solution makes exactly what the problem statement ask for?
      Btw, I saw this code harder to understand than mine.. at least for me, i think is because i know a little about LINQ, but, thanks a lot for your code! ;)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s