• This topic is empty.
Viewing 1 post (of 1 total)
  • Author
  • #219

      For key, these are the criteria:

      1. Only 26 characters

      2. Those 26 characters should be alphabets

      3. Each of the characters should be unique

      I believe the toughest one is to ensure each of the characters should be unique. On doing Google Search, I see a lot of ways to make sure if a string has all unique characters.



      Just to confirm, one of the above strategies need to be applied for the Substitution Project. If so, this will be a project in itself though should be a great learning experience.


      Here is my rough pseudocode after reading replies:

      Need to compare elements from argv[0] to argv[0][26]//there are 26 alphabets (0 – 25) plus one for end of array

      Check if

      1. argv[0][0] == argv[0][1]

      2. If yes,

      3. return 1,

      4. else argv[0][0] == argv[0][0] + 1

      5. till argv[0][24] // 25th alphabetic character argv[0][24] needs to be compared with 26th.

      6. Next, continue with argv[0][0] + 1 till argv[0][24] with line 1.


      et me simply put it like this. You have to compare each character of key with each character of key. Say your key is abcdd. How are you going to know if any of the character is repeated? You take first charater ‘a’ and compare it with each character of key except for the first. if a==key[1] and so on. We would get to know a is not repeated. Now what about second characted b. we take b and compare it with other chars of key started from char next to b and onwards.

      HINT: This “pseudocode” would hint you to use two loops.

      For a moment forget about coding in C. If I gave you this string: “ABCAD” … how would you as the human check if there are any duplicates? Don’t cheat by simply looking at it and determine the 1st and 4th letter both are ‘A’ 🙂

      How would you logically solve this?


      Start with the first object argv[1][0].

      The ASCII value of the first object is recorded – int argv[1][0].

      The second object argv[1][1] should not have ASCII value equal to one that is already recorded in argv[1][0].

      The task then would be to compare ASCII of each entered character with all the earlier ones entered. If similar, then return 1. Else continue.


      You don’t need to compare ASCII values, you can simply compare the characters 🙂

      So in the example above you would take the first letter, ‘A’, and compare to each of the other letters.

      When checking for ‘B’, you only need to focus on the other letters in the rest of the string, you already compared ‘B’ with the first letter.

      Be aware that ‘A’ and ‘a’ in this case is considered the same … just as to add a little spice to the challenge 🙂


    Viewing 1 post (of 1 total)
    • You must be logged in to reply to this topic.
    Scroll to Top