Array and Strings – Strings – Problem #5
IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive
Problem Statement
Submit one (single) C program. Write a C program to perform the following tasks. Definition of Hamming distance of two strings: Let there be 2 strings s1, s2 with respective lengths l1, l2 such that l1 <= l2 (wlog). Assuming the strings start with index 0, let the number of indices 0 <= i <= l2 - 1 where the two strings differ be t. All indices between l1 - 1 and l2 - 1 will be considered to be diferring. Then the Hamming distance of the two strings is t. Eg: The two strings abcd and bbdefgh are of respective lengths 4 and 7 and among the indices between 0 and 6, they differ in indices 0, 2, 3, 4, 5, 6. Therefore, the Hamming distance of the two strings is 6. 1. Define a structure user which stores 2 strings corresponding to the username and password of a user. Assume that a username or password can be of at most 100 characters. 2. In the main program, take as input a positive integer n. 3. Then take as input the details of n structures of type user. When taking the input for the ith structure, make sure that the ith username hs Hamming distance at least 1 from the previous i-1 usernames. 4. Ask a user to input their username and password. i) If the username does not match with any of the n usernames, output a message asking the user to register this username, and ask for a username and password again. If the username does not match after 3 attempts, write an error message ”You have used up all your attempts.” ii) If the username matches with one of the n usernames but the corresponding password s does not, then output an error message, and request for a new password. Let s' be the string entered as a new password. Now you have to make two checks with s and s': (a) If the s' has at least 1 vowel, (b) If the Hamming distance of s and s' is at most length(s.s')/3. Until both the conditions are satisfied, you have to keep asking for a suitable new password. Finally, replace s in the structure with s0 and output a message saying that the password has been reset. iii) If both username and password match, then output a message that the login was successful. You can write your own functions wherever necessary, but proper commenting is required to explain the purpose of the function. Functions from string.h can be used. Part-II Sample Output Enter positive integer: 2 Enter the username of user 1: userone Enter the password of user 1: pass Enter the username of user 2: userone This username is already taken. Enter the username of user 2: usertwo Enter the password of user 2: word Enter your username to login: user Enter your password to login: word This username is not registered! Enter your username to login: userone Enter your password to login: word Your password does not match, please enter a new password: word Thank you, your password has been reset.