Question

Code "string removeDuplicates(string original)" in C++. Please do as simple as possible!

Code "string removeDuplicates(string original)" in C++. Please do as simple as possible!

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <string>

using namespace std;

string removeDuplicates(string original) {
    string result;
    for (int i = 0; i < original.size(); ++i) {
        bool found = false;
        for (int j = 0; j < result.size(); ++j) {
            if (original[i] == result[j]) {
                found = true;
            }
        }
        if (!found) {
            result += original[i];
        }
    }
    return result;
}

int main() {
    cout << removeDuplicates("Hello how are you?") << endl;
    return 0;
}

Add a comment
Know the answer?
Add Answer to:
Code "string removeDuplicates(string original)" in C++. Please do as simple as possible!
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA Programming - Create a very simple single-class program (the most basic code form possible), which...

    JAVA Programming - Create a very simple single-class program (the most basic code form possible), which demonstrates the various concepts, methods, with comments explaining each part, following the topics: //Understanding String Data Problems // Comparing String Values //Empty and Null Strings //Using a Variety of String Methods //Converting String Objects to Numbers //StringBuilder and StringBuffer Classes

  • MATLAB ONLY PLEASE...ALSO AS SIMPLE AS POSSIBLE...NEW TO LANGUAGE Write a code that will ask the...

    MATLAB ONLY PLEASE...ALSO AS SIMPLE AS POSSIBLE...NEW TO LANGUAGE Write a code that will ask the user to input a positive number x. If the number is negative the program will keep asking again and again (as long as the value is negative) until the user inputs a positive value. At the end of the program, calculate the following: y = e-x

  • Intro To Java Class. AS SIMPLE AS POSSIBLE. Please post the pic of code, will up...

    Intro To Java Class. AS SIMPLE AS POSSIBLE. Please post the pic of code, will up Vote! You will need to use Blue) for the following questions. Although these are programming exercises, remember always that the first step to the program is to put your ideas on paper to organize your thoughts. Remember Section 1.6: The Programming Process. Centigrade to Fahrenheit Table Write a program that displays a table of the centigrade temperatures 0 through 20 and their Fahrenheit equivalents....

  • How do you determine the scope for risk management process? ​​​​​​​(simple and original answer please, no hand writing thx)

    How do you determine the scope for risk management process? ​​​​​​​(simple and original answer please, no hand writing thx)

  • Please write the following code as simple as possible in python: You will need to define...

    Please write the following code as simple as possible in python: You will need to define a function with four arguments. Here is what I used: > def find_matches(file1.txt, output1.txt, strings, value): file1.txt will contain a list of various strings. The program must copy from the first argument, and it should be written in the second argument (the second file, "output1.txt"). The third and fourth arguments will determine which specific strings will be copied over to the second file. For...

  • The original code using the gets() function is written below. You need to do (a) change...

    The original code using the gets() function is written below. You need to do (a) change the provided code so that you now use fgets() function to obtain input from the user instead of gets(), (b) make any other necessary changes in the code because of using fgets() function, and (c) fill in the code for the execute() function so that the whole program works as expected (a simple shell program). Note: part c is already done, and the execute...

  • Convert this C++ code to C to print all possible palindromes of a string #include <bits/stdc++.h>...

    Convert this C++ code to C to print all possible palindromes of a string #include <bits/stdc++.h> #include <iostream> #include<vector> using namespace std; bool isPalindrome(string strData, int first, int last) { while (first < last) { if (strData[first] != strData[last]) return false; first++; last--; } return true; } void allPalPartUtility(vector<vector<string> >&allPart, vector<string> &currentPart, int startPos, int endPos, string strData) { if (startPos >= endPos) { allPart.push_back(currentPart); return; } for (int co = startPos; co < endPos; co++) { if (isPalindrome(strData, startPos,...

  • MATLAB PLEASE MATLAB PLEASE most simple code possible 6. Determine which sequences are average power and plot 5 peri...

    MATLAB PLEASE MATLAB PLEASE most simple code possible 6. Determine which sequences are average power and plot 5 periods. For part (c), show that it is possible to express the sequence using a simple formula. As for the aperiodic signals, just plot 40 samples periodic. Hence, for the periodic ones, find their period (a) an (n) %3D2 cos(풍n + ) sin(n + 좋) 4sin(3Tn- (b) 2(n) (e) ra(n) (d) a(n) COs( sin(n) + 3cox(품n -) sin(동n + 좋) com(품끼) (e)...

  • Consider the following code that repeats a C++ string three times. string a = "Hello"; string...

    Consider the following code that repeats a C++ string three times. string a = "Hello"; string b = a + a + a; Suppose s is a C string, and t is declared as char t[100]; Write the equivalent code for C strings that stores the threefold repetition of s (or as much of it as will fit) into t. (C++)

  • Please do in java as simply as possible with code available for copy and comments. Provide...

    Please do in java as simply as possible with code available for copy and comments. Provide screenshots of code and how your incorporating the .txt file with the code. Write a program that reads in temperatures from the text file temps.txt (file given in the assignment). Write the minimum temperature, maximum temperature and the new array (temperatures plus 10) to a new file. The temperatures in file are: 83 87 81 88 90 92 95

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT