Passwords

Some computer programs try to prevent easily guessable passwords being used, by rejecting those that do not meet some simple rules. One simple rule is to reject passwords which contain any sequence of letters immediately followed by the same sequence.

For example:

  • APPLE Rejected (P is repeated)
  • CUCUMBER Rejected (CU is repeated)
  • ONION Accepted (ON is not immediately repeated)
  • APRICOT Accepted
  1. Write a program which inputs a password (between 1 and 10 upper case letters) and then prints Rejected if the password is rejected, or Accepted otherwise. Your program should then terminate.
    Sample run
    Password: BANANA
    Rejected
  2. Suppose the only valid letters are A and B; the password ABA cannot be made longer since both ABAA and ABAB will be rejected. What is the length of the shortest password that cannot be made longer, if A, B and C are valid? Give an example.