Answer to Question #157838 in C++ for Ikraam

Question #157838

Initialize a string of size 40. Write a program that prints all unique alphabets from string. After printing them sort them in ascending order.

For example: Hi world I am here to help you.

Unique characters are:  H, I, W, O, R, L, D, A, M, E, T, P, Y, U.

Sorted: A, D, E, H, I , L,M, O, P, R, T, U, W, Y


1
Expert's answer
2021-01-23T10:19:52-0500
#include <iostream>
#include <set>
#include <string>

using namespace std;

int main() {
    set<char> ans;
    string input;

    
    getline(cin, input);

    for (auto e: input) {
        if ((65 <= (int)e && (int)e <= 90) || (97 <= (int)e && (int)e <= 122))
            ans.insert(toupper(e));
    }

    cout << "Answer: ";
    for (auto e: ans) {
        cout << e << ' ';
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS