Given a string of length L. The task is to convert the string into a grid.
- No. of rows >= floor(√L)
- No. of columns <= ceil(√L)
Input : str = "haveaniceday" Output : have anic eday Explanation: sqrt(12) = 3.46, Rows = 4, Columns = 3 Input :str = "geeksforgeeks" Output : geek forg geek s
Note: Ensure that row*column >= length of the string
- If (row * column) is less than L then row is equally assigned to column.
- Make a 2d character array of (rows * column) size.
- Assign the values to the 2d character array from the characters of the given string.
- Print the 2d character array.
Below is the implementation of the above approach.
GEEK SFOR GEEK S
- Minimum cost to convert 3 X 3 matrix into magic square
- Convert characters of a string to opposite case
- Convert given string so that it holds only distinct characters
- Python | Convert a list of characters into a string
- Maximum perimeter of a square in a 2D grid
- Search a Word in a 2D Grid of characters
- Check if matrix can be converted to another matrix by transposing square sub-matrices
- Minimum number of steps to convert a given matrix into Diagonally Dominant Matrix
- Minimum number of steps to convert a given matrix into Upper Hessenberg matrix
- Minimum steps required to convert the matrix into lower hessenberg matrix
- Shortest distance between two cells in a matrix or grid
- Rearrange the characters of the string such that no two adjacent characters are consecutive English alphabets
- Permutation of a string with maximum number of characters greater than its adjacent characters
- Program to convert given Matrix to a Diagonal Matrix
- C++ program to Convert a Matrix to Sparse Matrix
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.