5. Write a program to remove any duplicate letters from a word and display the new word maintaining the original order. For example, bananas would become bans and bookkeeper would become bokepr. You may not use any special unique commands!

Respuesta :

Answer:

word = input('Enter a single word: ', 's');

n = length(word);

nodupWord = [];

for i = 1:n

  dup = false;

  c = word(i);

  for j = 1:i-1

      if word(j) == c

          dup = true;

          break;

      end

  end

  if ~dup

      nodupWord = [nodupWord, c]; %add the non-duplicate char to end

  end

end

disp(['Adjusted word: ', nodupWord])

Explanation:

The code is in Python.