Arnab Chakraborty

Arnab Chakraborty

3,768 Articles Published

Articles by Arnab Chakraborty

Page 307 of 377

Sort an array of strings according to string lengths in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

Here we will see how to sort a list of strings based on their lengths. So if a string has less number of characters, then that will be placed first, then other longer strings will be placed. Suppose the strings arestr_list = {“Hello”, “ABC”, “Programming”, “Length”, “Population”}after sorting, they will be −str_list = {“ABC”, “Hello”, “Length”, “Population”, “Programming”}Here we will create our own comparison logic to sort them. That comparison logic will be used in the sort function in C++ STL.Algorithmcompare(str1, str2): Begin    if length of str1 < length of str2, then       return 1    return ...

Read More

4 Keys Keyboard in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

Suppose we will try to write the letter ‘A’, using the keyboard. Our goal is to use only four keys and try to write maximum ‘A’s on the text field. The keys are ‘A’, ‘C’, ‘V’, and ‘Ctrl’. To write a maximum number of A, we will use Ctrl + A to select All, Ctrl + C to copy, and Ctrl + V to paste. So, if the input is like the number of keystrokes is 7 then the output will be 9 as of press A three times. Then Ctrl+A, Ctrl+C, Ctrl+V, Ctrl+V To solve this, we will follow ...

Read More

All reverse permutations of an array using STL in C++?

Arnab Chakraborty
Arnab Chakraborty
Updated on 21-Feb-2025 382 Views

In this problem, we need to generate all reverse permutations of a given array using C++'s Standard Template Library (STL). A permutation is simply rearranging the elements of the array in every possible order. For example, with an array of three elements, there are six possible ways to arrange them. For each of these permutations, we need to reverse the order of the elements and then print the results. The goal is to first generate all possible permutations of the array, then reverse each one before displaying them. Example Scenario: Let's say we have the array {1, 2, 3}. ...

Read More

How to sort an Array using STL in C++?

Arnab Chakraborty
Arnab Chakraborty
Updated on 21-Feb-2025 2K+ Views

The problem is to sort an array using C++'s Standard Template Library (STL). Sorting an array means rearranging its elements in a specific order. In this case, we aim to sort the elements in both ascending and descending order, using the built-in functionalities of the STL. Let's say we have the following array of integers: int arr[] = {4, 2, 9, 1, 7}; The goal is to sort this array so that the elements are ordered from smallest to largest (ascending) and largest to smallest (descending): Ascending: arr = {1, 2, 4, 7, 9} Descending: arr = {9, 7, ...

Read More

How to find the maximum element of an Array using STL in C++?

Arnab Chakraborty
Arnab Chakraborty
Updated on 14-Feb-2025 4K+ Views

In C++, one common task is to find the largest number in an array. An array is just a collection of values, and sometimes we need to find the highest value in that collection. For example, consider the array: int arr[] = {11, 13, 21, 45, 8}; In this case, the largest element is 45. Similarly, for the array: int arr[] = {1, 9, 2, 5, 7}; The largest number is 9. In this article, we will show you how to find the largest number in an array using different methods in C++, including some built-in features ...

Read More

C++ program to convert the string into an integer

Arnab Chakraborty
Arnab Chakraborty
Updated on 09-Dec-2024 13K+ Views

C++ is a statically typed language. To write programs we need to define variables of specified types. Sometimes we need to read inputs from the console or files. In such a scenario the string data are read into the program. To convert them into other datatypes needs special operations. In this article, we shall discuss how to convert strings to integers in C++. There are a few different techniques to do so. Let us explore them one by one. String to Integer Using stringstream Class C++ uses streams for different applications. Such streams are filestreams, standard input/output streams, etc. There ...

Read More

5 Different methods to find length of a string in C++?

Arnab Chakraborty
Arnab Chakraborty
Updated on 05-Dec-2024 12K+ Views

Here we will see five different ways to get the string lengths in C++. In C++ we can use the traditional character array string, and C++ also has String class. In different area there are different methods of calculating the string lengths. The C++ String class has length() and size() function. These can be used to get the length of a string type object. To get the length of the traditional C like strings, we can use the strlen() function. That is present under the cstring header file. Another two approaches are straight forward. One by using the while loop, ...

Read More

Matrix Chain Multiplication (A O(N^3) Solution) in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 02-Dec-2024 4K+ Views

If a chain of matrices is given, we have to find a minimum number of correct sequences of matrices to multiply. We know that the matrix multiplication is associative, so for four matrices ABCD, we can multiply A(BCD), (AB)(CD), (ABC)D, and A(BC)D, in these sequences. Like these sequences, our task is to find which ordering is efficient to multiply.ExampleIn the given input there is an array say arr, which contains arr[] = {1, 2, 3, 4}. It means the matrices are of the order (1 x 2), (2 x 3), (3 x 4). Input − The ...

Read More

C++ program to overload addition operator to add two complex numbers

Arnab Chakraborty
Arnab Chakraborty
Updated on 31-Oct-2023 37K+ Views

Suppose we have a complex number class with real and imaginary part. We shall have to overload the addition (+) operator to add two complex number. We also have to define a function to return complex number in proper representation.So, if the input is like c1 = 8 - 5i, c2 = 2 + 3i, then the output will be 10 - 2i.To solve this, we will follow these steps −Overload the + operator and take another complex number c2 as argumentdefine a complex number called ret whose real and imag are 0real of ret := own real + real ...

Read More

C++ Program to append an element into an array

Arnab Chakraborty
Arnab Chakraborty
Updated on 04-Oct-2023 50K+ Views

An array is a linear sequential data structure to hold homogeneous data in consecutive memory locations. Like other data structures, an array also must-have features to insert, delete, traverse and update elements in some efficient way. In C++, our arrays are static. There are a few dynamic array structures also available in C++. For a static array, there may be a Z number of elements that can be stored inside that array. And till now we have n elements into it. In this article, we will see how to insert an element at the end of an array (which is ...

Read More
Showing 3061–3070 of 3,768 articles
« Prev 1 305 306 307 308 309 377 Next »
Advertisements