Friday, 8 February 2013

Tech C: DMR Programming contest


Tech C: DMR Programming contest

I-Know-Vention

 

Instructions:

Please solve as many of the following as possible. These are the practice questions for you.

We wish, you will be the one amongst the 600 high rank contestants who will be invited for the programming contest after the on-line quiz through FB is over. You will be given 1 randomly selected question out of this list of 20. You will have to generate a solution within an hour. There will be some marks for following the best programming practices as well.

 

List of questions:

 

1 Given: A line is comprised of one or more words that are separated by a space or a tab.(It should not contain unnecessary multiple tabs or spaces). End of a line is denoted by an EOF symbol. Write a program that reads a text file and converts it to a sequence of lines as per the definition above. If the length of a line exceeds 80 characters, introduce one blank line after printing the same it.

I/p: a human       can  play the role of a computer
if there is an instruction set that                the human can perform unthinkingly                     without using creativity or imagination       then he or she is indeed an instruction set processor and hence a computer
sit stand sleep can form an instruction set

Expected O/P:

a human can play the role of a computer
if there is an instruction set that the human can perform unthinkingly without using creativity or imagination then he or she is indeed an instruction set processor and hence a computer

sit stand sleep can form an instruction set

(Note: in the o/p above, In a line multiple space or tabs are replaced by single tab or space,a blank line is left in between when length of line exceeds 80 characters)

2 Write a program to copy its input to its output replacing each tab by the string “Tab”, white space by “Blank” and backslash by “BackSlash”. In case of successive tabs or blanks or backslashes, the output should be appropriately designed. For example, occurrence \\\ should be replaced by “3 blackslashes”.   

I/p: \\\If there is an instruction set that the human can perform unthinkingly

Expected O/p: “3backslashes”if”Blank”there”Blank”is”Blank”an”Blank”instruction”Blank”set”Blank”that“Tab” the”Blank”human”Blank”can”Blank”perform”Balnk” unthinkingly

 

3 Write a program that checks a C program for rudimentary syntax errors like mismatched brackets, parenthesis, braces, quotes and comments.  

I/p: #include <stdio.h>          
 
int main()                           /* Most important part of the program!
*/
{
    int age;                          /* Need a variable... *//
 
    printf( "Please enter your age" );  /* Asks for age */
    scanf( "%d", &age );                 /** The input is put in age **/
    if ( age < 100 ) {  }               // /* If the age is less than 100 */
     printf ("You are pretty young!\n" ); /* Just to show you it works... */
  }
-------------------------------------------------------------------------------------------------------------------------
O/p: #include <stdio.h>        
 
int main()                           /* Most important part of the program!
*/
{
    int age;                          /* Need a variable... *//
 
    printf( "Please enter your age";  /* Asks for age */
    scanf( "%d", &age );                 /** The input is put in age **/
    if ( age < 100 ) { }                // /* If the age is less than 100 */
     printf ("You are pretty young!\n" ); /* Just to show you it works... */
  }}

 

4 Write a program that plots a graph of word-length vs. frequency of the words of the specific length in the given text.

I/p: We can call this blank the operand

O/P: Histogram of {(2,1), (3,2), (4,2), (5,1), (7,1)}

Note: {(word-length, occurrence)}

 

5 Write a program to generate all strings of length upto k on a given set of symbols.     (Hint: I/p:Take 6 symbols in the lower-case English alphabet {a, b, c, d, e, f} and k = 3; print the first 25 strings of your output sorted by length.)

O/p: a,b,c,d,e,f,aa,ab,ac,ad,ae,af, ba, bb...

 

 

6 Write a program to generate all strings of length upto k on a given set of symbols.

I/p: Take 6 symbols in English alphabet = {a, b, c, d, e, f} and k = 3; print first 25 strings of your output sorted in dictionary order

O/p: a,aa,aaa, aab,aac.......aaf, aba,abb...

 

7 Write a program to generate all strings of length upto k on a given set of symbols sorted in dictionary order.

I/p: Take 6 symbols in English alphabet = {a, b, c, d, e, f} and k = 3;

O/p: a,aa,aaa, aab,aac.......aaf, aba,abb...

 

Write a program to compute the index of an inputed letter-string in above list

i/p: aac

O/p: 5

8 Write a program to generate all strings of length upto k on a given set of symbols. No symbol should be repeated in any string. 

I/p: Take the 6 lower-case symbols in the English alphabet {a, b, c, d, e, f} and k = 3; print the first 25 strings of your output sorted in dictionary order

O/p: a,ab, aba, ...

 

9 (kamal, mina, asmaa, aaditya, abdul, kshitij, mary, amrit, sanjeevan, pritha, kiran) is a list of names of my classmates. Write a program that reads a letter and displays all the names that are starting with that letter. Remember, your search should be faster and it should avoid searching/traversing entire list every time for inputted letter.

(Hint: Use suitable datastructure to write an efficient program)

I/p: a
O/p:
asmaa, aaditya, abdul, amrit

i/p:m    o/p:mina,mary

 

10 Write a program that computes b(n/d) where b, n and d are integers.

 

I/p: b = 3, n = 4 and d = 2
O/p: 9

 

11{kamal, vimal, asmaa, aaditya, abdul, kshitij, mary, amrit, sanjeevan, pritha, kiran} is a set of names of my classmates. Write a program that takes a name and tells if the person is my classmate or not. In any case, your search should not involve more than one comparison.(Hint: Use suitable datastructure)

12 Create an animation of stars falling from sky to ground and vanishing. Press any key to
terminate

13 Write a program that does the following: The letters of English alphabet are randomly generated and accumulated in a bin. If at any instance it is possible to form a word out of the letters in the bin, the word is formed and displayed. The program ends here. You can always terminate the program by pressing any key in between.

14 Write a program that reads a line and aligns the text to both the right and left margins by adding spaces between the words as necessary.

I/p: like addition or multiplication, we consider the instruction as an operation to be performed

 

15 Given m different routes between n cities, 2 new cities that are connected with all n cities, write a program to find the shortest route that connects all n+2 cities. Assume that the adjacent cities are at unit distance.

I/p: Set of adjacent cities is given as {(1,4), (1,6), (2,3), (3,4), (5,7)}

 

16 Write a program for matchstick game between the computer and a user. Your program should ensure that computer always wins. Rules for the game are as follows:

R1: There are 21 matchsticks
R2: The computer asks the player to pick 1, 2, 3 or 4 matchsticks
R3: After the person picks, the computer plays by picking 1, 2, 3 or 4 sticks
R4: The one who is forced to pick up the last matchstick loses the game.

17 Write a program that prints a histogram of frequencies of different characters in its input.

I/p: To know what is your username, type at the prompt who space am space I and press enter.

 

18 Write an intelligent editor to simulate the following:
While typing if a new word starts with the same letters as that of some previously typed word, the choice of selecting the word instead of typing the whole should be given. 

I/p: This in fact comes from the who command that enlists all the users currently logged into the system in case your system is a multiuser system.

19 Write a program that generates a random number of length 25.

20 Write a program called reverse_input for the following behaviour: (1) If the input is a single word, then the output has the word in reverse order, i.e., the last letter of the input word will become the first letter of the output string, the second-last input letter becomes the second output letter and so on.  (2) If the input is a single line with several words, then the output has the words in reverse order (but the letters in the words are not reversed).  (3) If the input has several lines, then the output has the lines in reverse order (without changing the order of the words in each line).

I/p: (i) word     (ii) One line answer   

O/p: (i) drow   (ii) Answer line one

No comments:

Post a Comment