● Writing code is like art; Do it beautifully with Indentation and Comments ● Don’t cram everything in the main function, create a different function for each question
*OJ submission
1. Read about the function, string and scope of variables.
2. Important inbuilt functions: strlen, s trcmp and strcpy. 3. *Write a function which takes two integers n and b, and returns the number of digits in base b representation of n. Initially, n is in decimal. 4. *Write a C code to compute the nth Fibonacci number using two different functions. 4.1. What is the time and space complexity of the function? 4.2. Can you optimize that function so that it takes less time? What is the trade-off? 5. Given a string S, write a C code to check if S is a palindrome. 6. Give the frequency distribution of an alphanumeric string S given as input. 6.1. 1 <= |S| <= 106 6.2. Sample input: 0The1Quick2Brown3Fox4Jumps5Over6The7Lazy8Dog9 6.3. Sample output: similar to the link above, it would be better if you can differentiate uppercase and lowercase. 7. Given a string S and T, find if T is a substring, subsequence or subset of S. 7.1. Substring: X is a substring of Y is there exist a continuous segment in Y which is equal to X. 7.2. Subsequence: X is a subsequence of Y is you can form X from Y by deleting some characters from Y without changing the order of the remaining string. A subsequence is generalization of a substring. 7.3. Subset: X is a subset of Y if X is can be formed from Y by deleting and rearranging certain characters of Y. A subset is generalization of a subsequence. 7.3.1. Note: X and Y are anagrams or permutation if X is a subset of Y and |X| = |Y|. 7.4. Example: Let B = “CProgLang” 7.5. For A = “rog”, A is a substring, subsequence and subset of B. 7.6. For A = “roL” or A = “CPL”, A is a subsequence and subset of B. 7.7. For A = “CLP” or A =”aCLo”, A is a subset of B. 7.8. What is the complexity of the code? Can you improve them? 8. (Bonus) Read about Caesar cipher. Use the link to decode. Write an interactive code which has input as a string S encrypted by Caesar shift cipher and you need to decode. Each query to the code must be of the following format: 8.1. S <i>, shift the input string by i; 0 <= i < 26, but don’t change the input string 8.2. D <i>, shift the input string by i and change the input string, and terminate the code; 0 <= i < 26 Sample Input 1 for 8: Ifmmp Interactive Input Interactive Output S0 Ifmmp S1 Jgnnq S 25 Hello D 25 Hello
Sample Input 2 for 8:
World Interactive Input Interactive Output D0 World