Sorting and 2d Arrays – Geometry – Problem #2

IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive

Difficulty: hard

Problem Statement

A square 2D character array of size nXn is called ‘character-mirrored’ if it satisfies the following condition. • Consider all the left diagonals of the array except the principal left diagonal, the upper right corner element of the array and the lower left corner element of the array. A symmetric pair of left diagonals is such a pair which consists of an upper left diagonal and a lower left diagonal, both separated equally from the principal left diagonal. If, for ALL symmetric pairs of left diagonals of the array, the characters (elements) of upper left diagonal of each symmetric pair is equal to the reverse order of the characters (elements) of its corresponding lower left diagonal of that symmetric pair, then the array is called ‘character-mirrored’, otherwise it is not ‘character-mirrored’. For example, consider a 4x4 character array: Now consider the same array with different color codings to help you understand Principal left diagonal = [A, F, K, P] (shown in red) Upper right corner element = D (highlighted in blue) Lower left corner element = M (highlighted also in blue) 1st symmetric pair (highlighted in yellow both above and below the principal left diagonal): Upper left diagonal = [B, G, L] Lower left diagonal = [L, G, B] 2nd symmetric pair (highlighted in green both above and below the principal left diagonal): Upper left diagonal = [C, H] Lower left diagonal = [H, C] Now consider the two symmetric pairs. For the 1st pair the characters in the upper left diagonal are exactly the reverse of the characters of the lower left diagonal. For the 2nd symmetric pair also, the same observation can be made. Hence this particular 2D character array is ‘character- mirrored’. Write a C program to input an n X n 2D character array and print all pairs of symmetric left diagonals. Also, check whether the 2D array is ‘character-mirrored’ or not.

Back to Lab Problems
Sorting and 2d Arrays/Geometry/Problem #2

Lab Problem Statement

Specifications & Problem DetailsIIT Kharagpur PDS Archive
Loading question...

Interactive C Compiler · Problem #2

WASM In-Browser

Runs directly on your machine · Zero remote server dependency

Compiler downloads on first Run (large, saved in your browser after that)
main.cCtrl + Enter to run
1
2
3
4
5
6
7
Input (stdin)given to scanf / cin
Output

Output appears here. Press Run to compile and execute.