Posts

Shift Characters Upwards

 Shift Characters Upwards  PROBLEM STATEMENT : The program must accept N string values of equal length L and an integer K as the input. The program must perform the following operation K times. - Shift the middle L-2 characters towards the top by one position among the given N string values. Finally, the program must print the N modified string values as the output.  Boundary Condition(s): 2 <= N <= 100  3 <= Length of each string <= 100  1 <= K <= 10^8  Input Format:  The first line contains N.  The next N lines, each contains a string value.  The (N+2)nd line contains K.  Output Format:  The first N lines containing the N modified string values.  Example Input/Output 1: Input: ( ) 5 coding across expert office travel 1 Output: ccrosg axpers effict oravee todinl Explanation:  Here N = 5 and K = 1.  The length of each string is 6.  K = 1: After shifting the middle 4(6-2) chara...

String Matrix to Character Matrix

 String Matrix to Character Matrix  PROBLEM STATEMENT : The program must accept a matrix of size RxC containing only words as the input. All words in the matrix have the same length as 9. The program must form a character matrix of size (R*3)x(C*3) by expanding the each word to a 3*3 character matrix based on the following conditions. - The 1st row of the 3*3 matrix must be formed using the first 3 characters of the word. - The 2nd row of the 3*3 matrix must be formed using the middle 3 characters of the word. - The 3rd row of the 3*3 matrix must be formed using the last 3 characters of the word. Finally, the program must print the character matrix as the output.  Boundary Condition(s):   1 <= R, C <= 50  Input Format:  The first line contains R and C separated by a space.  The next R lines, each contains C words separated by a space.  Output Format:  The first R*3 lines, each contains C*3 characters separated by a space.  Examp...

Very Hard Integers

 Very Hard Integers  PROBLEM STATEMENT : The program must accept two integers N and H as the input. If the binary representation of an integer contains 101 , then it is a hard integer. The hardness of an integer H is equal to the number of occurrences of 101 in its binary representation (with overlapping). The program must print the number of integers from 1 to N having the hardness greater than or equal to H as the output.  Boundary Condition(s):  1 <= N <= 10 6   1 <= H <= 9  Input Format:  The first line contains N and H separated by a space.  Output Format:   The first line contains an integer representing the number of integers from 1 to N having the hardness greater than or equal to H.  Example Input/Output 1: Input: ( ) 50 1 Output: 20 Explanation:   Here N = 50 and H = 1 .  The integers having the hardness greater than or equal to 1 are given below.  5 -> 101 -> H = 1  10 -> 1010...

Multi-Storey Car Parking Lot

 Multi-Storey Car Parking Lot PROBLEM STATEMENT :  The program must accept an integer matrix of size R*C representing a multi-storey car parking lot. The integer 0 represents an empty slot and the integer 1 represents a car. The entry point is always present at the bottom-right of the ground floor. The way to reach the 1st floor is on the left side of the ground floor. The way to reach the 2nd floor is on the right side of the 1st floor. Similarly, the ways to the remaining floors are present on the left side and right side alternatively. A person wants to park his car in the first occurring empty slot on or above the Xth floor. The value of X is also passed as the input. The program must print the instructions he needs to follow to park his car as the output. The instructions must be in the following formats. -> L followed by an integer K - It indicates that he needs to move K slots towards left.  -> R followed by an integer K - It indicates that he needs to move ...

Construction of New Buildings

Construction of New Buildings  PROBLEM STATEMENT : The program must accept a character of size R*C representing a city as the input. The matrix consists of asterisks and hyphens. Each asterisk represents a building and each hyphen represents a land. The government has planned to construct new buildings in the city based on the following condition.  - If a land is present in one of the four corners (top-left, top-right, bottom-left and bottom-right) of a building, then a new building is allowed to construct on that land.  The program must print the maximum number of new buildings that can be built based on the given conditions.  Boundary Condition(s):   2 <= R, C <= 50  Input Format:   The first line contains R and C separated by a space.  The next R lines, each contains C characters separated by a space.  Output Format:   The first line contains the maximum number of new buildings that can be built.  Example Input/Output 1...

Binary - Case Sensitive Decryption

Binary - Case Sensitive Decryption  PROBLEM STATEMENT : The program must accept a string S representing an encrypted message as the input. The program must decrypt the string S and print the message based on the following conditions.  - The program must split the string S into substrings of equal length 5 .  - For each substring, the program must form a binary representation by replacing the lower case alphabets with 0 and the upper case alphabets with 1 .  Then the program must find the decimal equivalent of each binary representation and replace them with the characters as given below. From 0 to 25 -> a to z.  26 -> . (dot)  27 -> , (comma)  28 -> a SPACE character  29 -> ? (question mark symbol)  30 -> ' (single quote)  31 -> " (double quote)  Note: The string S contains only alphabets and its length is always a multiple of 5.  Boundary Condition(s):  1 <= Length of S <= 1000...

Alternate Sorting of Numbers

 Alternate Sorting of Numbers PROBLEM STATEMENT : Given an array of integers, rearrange the array in such a way that the first element is first maximum and second element is first minimum. The third element must be second maximum and fourth element must be second minimum and so on.  Input Format:  The first line will contain the numbers separated by a space.  Boundary Conditions:  Length of the input string will be from 3 to 200.  Output Format:   The numbers separated by a single space as per the mentioned conditions.  Example Input/Output 1: Input: ( ) 2 3 4 7 Output: 7 2 4 3 Example Input/Output 2: Input: ( ) 1 2 3 4 5 6 7 Output: 7 1 6 2 5 3 4 Example Input/Output 3: Input: ( ) 23 55 Output: 55 23 SOLUTION : C (Programming Language) Copy Code #include<stdio.h> #include<stdlib.h> int fun(const void *a,const void *b) { return (*(int*)a - *(int*)b); } int main() { int n=-1,a[201],i; while(scanf...