Marinda
Marinda

Reputation: 1

How to put given characters into alphabetical order with the uppercase letters in the front

There will be a given input by the user and I have to put it into alphabetical order with the uppercase characters in the front, lowercase after. C++ For example, the input is GoodMorning, the output will be GMdginnooor.

Upvotes: 0

Views: 38

Answers (1)

Rohan Bari
Rohan Bari

Reputation: 7726

It's pretty simple, just use the following:

#include <iostream>
#include <algorithm>

int main(void)
{
    std::string text;

    std::cout << "Input a string: ";
    getline(std::cin, text);

    std::sort(text.begin(), text.end());

    std::cout << text;

    return 0;
}

Sample Output

Input a string: GoodMorning
GMdginnooor

Hope it helps you!

Upvotes: 1

Related Questions