Consider the following program.• Fill in the blank at LINE-1 with the appropriate header of max str( ).• Fill in the blank at LINE-2 with the appropriate statements such that the string array can be sorted in descending order.The program must satisfy the sample input and output.Input: Lion Tiger Bear Hippo BullOutput: Tiger Lion Hippo Bull Bear
Question
Consider the following program.• Fill in the blank at LINE-1 with the appropriate header of max str( ).• Fill in the blank at LINE-2 with the appropriate statements such that the string array can be sorted in descending order.The program must satisfy the sample input and output.Input: Lion Tiger Bear Hippo BullOutput: Tiger Lion Hippo Bull Bear
Solution
The question seems to be asking for a solution in C++ language. Here is how you can solve it:
At LINE-1, you need to include the algorithm header file to use the max_element function. So, the code would be:
#include <algorithm>
At LINE-2, you need to sort the array in descending order. You can use the sort function from the algorithm library and provide a custom comparator to sort in descending order. So, the code would be:
std::sort(str, str + n, std::greater<std::string>());
So, the complete code would look something like this:
#include <iostream>
#include <algorithm>
#include <string>
int main() {
std::string str[] = {"Lion", "Tiger", "Bear", "Hippo", "Bull"};
int n = sizeof(str)/sizeof(str[0]);
// LINE-1
#include <algorithm>
// LINE-2
std::sort(str, str + n, std::greater<std::string>());
for (int i = 0; i < n; i++)
std::cout << str[i] << " ";
return 0;
}
This program will output: "Tiger Lion Hippo Bull Bear", which is the array sorted in descending order.
Similar Questions
program must accept two string values S1 (may contain space) and S2 (one word) as the input. The words in S1 are sorted lexicographically and separated by exactly one space. The program must insert the the string S2 in S1 such that all the words in the modified S1 are also in sorted order.Note: The string values contain only lower case alphabetsBoundary Condition(s):1 <= Length of S1 <= 10001 <= Length of S2 <= 100Input Format:The first line contains S1.The second line contains S2.Output Format:The first line contains the modified S1.Example Input/Output 1:Input:abacus ball dog hat mind zebrainkOutput:abacus ball dog hat ink mind zebraExample Input/Output 2:Input:captain celbrate cricketcrackerOutput:captain celbrate cracker cricket
The program must accept N integers as the input. The program must sort the N integers using selection sort and print all the iterations of the selection sorting process as the output.Boundary Condition(s):2 <= N <= 1001 <= Each integer value <= 1000Input Format:The first line contains N.The second line contains N integers separated by a space.Output Format:The lines containing all the stages of the selection sort.Example Input/Output 1:Input:512 6 15 9 10Output:6 12 15 9 106 9 15 12 106 9 10 12 156 9 10 12 15
Write a program to print each character of a string in incremental order.Write a program to print each character of a string in incremental order as shown in the sample test cases.Sample Test CasesTest Case 1:Expected Output:str:·Keyincremental·order:·KKeKeyTest Case 2:Expected Output:str:·Pythonincremental·order:·PPyPytPythPythoPythonSubmit12345str·=·input("str:·")¬¬¬¬print("incremental·order:",···)¶
Problem StatementIn a computer science class, students are assigned unique identification letters based on their seating arrangement. Each student has a specific letter, and you are tasked with creating a program to sort these letters in ascending order using the bubble sort algorithm. The sorting should be based on their ASCII values. Input the total number of students and their assigned letters, then display the sorted list, allowing the students to easily identify their seating order.Input format :The first line of input consists of an integer N, representing the total number of students.The second line consists of N space-separated characters, each representing the unique identification letter assigned to a student.Output format :The output prints the sorted list of identification letters based on their ASCII values.Refer to the sample output for formatting specifications.Code constraints :1 ≤ N ≤ 15Each identification letter is a valid ASCII character.The input characters are case-sensitive.Sample test cases :Input 1 :5a y h j oOutput 1 :a h j o y Input 2 :7Q G Y O M N BOutput 2 :B G M N O Q Y Input 3 :8a e T V z X h KOutput 3 :K T V X a e h z
You are given an array of strings arr. A string s is formed by the concatenation of a subsequence of arr that has unique characters.Return the maximum possible length of s.A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements. Example 1:Input: arr = ["un","iq","ue"]Output: 4Explanation: All the valid concatenations are:- ""- "un"- "iq"- "ue"- "uniq" ("un" + "iq")- "ique" ("iq" + "ue")Maximum length is 4.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.