Found 7347 Articles for C++

Rearrange the given source code in C++

Sunidhi Bansal
Updated on 02-Nov-2021 07:37:58

277 Views

We are given a string type variable, let's say, str which will be used to store the source code then calculate the size of the string and pass it to the function. The task is to rearrange the given source code and then print the result.Let us see various input output scenarios for this −Input − string str ="#include using namespace std; int main()"    "{ int sum, first, second; sum = first + second; printf(\"%d\", c);"    " return 0;}"Output −#include using namespace std; int main(){    int sum, first, second;    sum = first + second;    printf("%d", ... Read More

Rearrange the string to maximize the number of palindromic substrings in C++

Sunidhi Bansal
Updated on 02-Nov-2021 07:15:32

218 Views

We are given with a string ‘str’ of any given length. The task is to rearrange the characters in such a manner that there will be maximum substrings that will be a palindrome string without adding or removing a character from the given input string. Palindrome string is the one in which the characters are arranged in such a manner that they pronounce the same from start and last.Let us see various input output scenarios for this −Input − string str = "itnin"Output − Rearrangement of the string to maximize the number of palindromic substrings is: iinnt.Explanation − We are given a string ... Read More

Rearrangement of a number which is also divisible by it in C++

Sunidhi Bansal
Updated on 02-Nov-2021 07:13:10

272 Views

We are given an integer type number, let's say, number. The task is to rearrange number digit’s in such a manner that a number formed after rearrangement is also divisible by the given number i.e. ’number’.Let us see various input output scenarios for this −Input − int number = 100035Output − Rearrangement of a number which is also divisible by it is: 300105Explanation − we are given an integer number as ‘number’ i.e. 100035. Now, the task is to rearrange these given digits in such a manner that the formed number will be divisible by 100035. So, after rearranging the digits we got ... Read More

Rearrange characters to form palindrome if possible in C++

Sunidhi Bansal
Updated on 02-Nov-2021 07:09:53

855 Views

We are given with a string ‘str’ of any given length. The task is to rearrange the characters in such a manner that the output will be a palindrome string without adding or removing a character from the given input string. Palindrome string is the one in which the characters are arranged in such a manner that they pronounce the same from start and last.Let us see various input output scenarios for this −Input − string str = "itnin"Output − Rearrangement of characters to form palindrome if possible is: nitinExplanation − We are given a string type variable let’s say, str. Now we ... Read More

Rearrange Odd and Even values in Alternate Fashion in Ascending Order in C+=+

Sunidhi Bansal
Updated on 02-Nov-2021 07:06:34

1K+ Views

We are given an integer type array containing both positive and negative numbers, let's say, arr[] of any given size. The task is to rearrange an array in such a manner that when the lowest element in an array is odd then elements of an array will be rearranged in odd first and even second manner. When the lowest element in an array is even then elements of an array will be rearranged in even first and odd second manner and if the number of even/odd elements is more than the number of odd/even elements then it will place the ... Read More

Rearrange first N numbers to make them at K distance in C++

Sunidhi Bansal
Updated on 02-Nov-2021 06:57:56

71 Views

We are given integer variables, let's say, N and K. The task is to firstly calculate the permutation of N and then rearrange the permutation in such a manner that it will be K distance from every element.Let us see various input output scenarios for this −Input − int n = 20, int k = 2Output − Rearrangement of first N numbers to make them at K distance is: 3 4 1 2 7 8 5 6 11 12 9 10 15 16 13 14 19 20 17 18.Explanation − we are given integer variables ‘N’ i.e. 20 and ‘K’ i.e. 2. Now ... Read More

Rearrange positive and negative numbers with constant extra space in C++

Sunidhi Bansal
Updated on 02-Nov-2021 06:54:58

270 Views

We are given an integer type array containing both positive and negative numbers, let's say, arr[] of any given size. The task is to rearrange an array in such a manner that all the elements of an array are sorted using the inbuilt sort function of C++ STL as well as using recursive technique of coding and printing the result.Let us see various input output scenarios for this −Input − int arr[] = {4, 2, -1, -1, 6, -3, 0}Output − Rearrangement of positive and negative numbers with constant extra space is: -3 -1 -1 0 6 2 4.Explanation − we are given ... Read More

Rearrange positive and negative numbers using inbuilt sort function in C++

Sunidhi Bansal
Updated on 02-Nov-2021 06:51:10

986 Views

We are given an integer type array containing both positive and negative numbers, let's say, arr[] of any given size. The task is to rearrange an array in such a manner that all the elements of an array are sorted using the inbuilt sort function of C++ STL as well as using recursive technique of coding and printing the result.Let us see various input output scenarios for this −Input − int arr[] = {4, 2, -1, -1, 6, -3, 0}Output − Rearrangement of positive and negative numbers using inbuilt sort function is: -3 -1 -1 0 2 4 6.Explanation − we are given ... Read More

Rearrange positive and negative numbers in O(n) time and O(1) extra space in C++

Sunidhi Bansal
Updated on 02-Nov-2021 06:48:28

285 Views

We are given an integer type array containing both positive and negative numbers, let's say, arr[] of any given size. The task is to rearrange an array in such a manner that all positive and negative numbers should be at alternate positions and if there are extra positive or negative elements then they will be placed in the end of an array.Let us see various input output scenarios for this −Input − int arr[] = {4, 2, -1, -1, 6, -3}Output − Rearrangement of positive and negative numbers in O(n) time and O(1) extra space is: 2 - 1 6 -1 4 ... Read More

Rearrange array such that even positioned are greater than odd in C++

Sunidhi Bansal
Updated on 02-Nov-2021 06:43:15

211 Views

We are given an integer type array containing both positive and negative numbers, let's say, arr[] of any given size. The task is to rearrange an array in such a manner that all the elements at an even position or index should be greater than the elements at an odd position or index and print the result.Let us see various input output scenarios for this −Input − int arr[] = {2, 1, 4, 3, 6, 5, 8, 7}Output − Array before Arrangement: 2 1 4 3 6 5 8 7 Rearrangement of an array such that even positioned are greater than odd ... Read More

Advertisements