Difficulty Level: Rookie
Write a program to print N equal parts of a given string.
1) Get the size of the string using string function strlen() (present in string.h)
2) Get size of a part.
part_size = string_length/n
3) Loop through the input string. In loop, if index becomes multiple of part_size then put a part separator(“\n”)
a_simpl e_divid e_strin g_quest
In above solution, n equal parts of the string are only printed. If we want individual parts to be stored then we need to allocate part_size + 1 memory for all N parts (1 extra for string termination character ‘\0’), and store the addresses of the parts in an array of character pointers.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Split a string in equal parts such that all parts are palindromes
- Divide a number into two parts
- Partiton the string in two parts such that both parts have at least k different characters
- Divide large number represented as string
- Longest sub-string having frequency of each character less than equal to k
- Program to check if first and the last characters of string are equal
- Count number of equal pairs in a string
- Find an equal point in a string of brackets
- Character whose frequency is equal to the sum of frequencies of other characters of the given string
- Check length of a string is equal to the number appended at its last
- Append a digit in the end to make the number equal to the length of the remaining string
- Form lexicographically smallest string with minimum replacements having equal number of 0s, 1s and 2s
- Partition a number into two divisble parts
- Longest Common Prefix using Divide and Conquer Algorithm
- Karatsuba algorithm for fast multiplication using Divide and Conquer algorithm