Question

In: Computer Science

Create a function that keeps only strings with repeating identical characters (in other words, it has...

Create a function that keeps only strings with repeating identical characters (in other words, it has a set size of 1).

Examples:

identicalFilter(["aaaaaa", "bc", "d", "eeee", "xyz"]) ➞ ["aaaaaa", "d", "eeee"]

identicalFilter(["88", "999", "22", "545", "133"]) ➞ ["88", "999", "22"]

identicalFilter(["xxxxo", "oxo", "xox", "ooxxoo", "oxo"]) ➞ []

Notes A string with a single character is trivially counted as a string with repeating identical characters. If there are no strings with repeating identical characters, return an empty array.

Code in C++ language ?

Solutions

Expert Solution

Code:

#include <bits/stdc++.h>
using namespace std;

vector<string> identicalFilter(vector<string> input){
        vector<string> ans;
        for(auto c:input)
        {
                set<char> s(c.begin(), c.end());
                if(s.size()==1)
                        ans.push_back(c);
        }
        return ans;
}

void print(vector<string> v){
    cout<<"[";
        for(int i=0;i<v.size();i++)
        cout<<v[i]<<", ";
    cout<<"]";
        cout<<endl;
}
int main() {
vector<string> ans = identicalFilter(vector<string>{"aaaaaa", "bc", "d", "eeee", "xyz"});
print(ans);
ans = identicalFilter(vector<string>{"88", "999", "22", "545", "133"});
print(ans);
ans = identicalFilter(vector<string>{"xxxxo", "oxo", "xox", "ooxxoo", "oxo"});
print(ans);
return 0;
}

Please comment in case of doubts or queries.
Kindly upvote :)


Related Solutions

Write a C++ function to sort the characters in words in a inputed phrase. DO not...
Write a C++ function to sort the characters in words in a inputed phrase. DO not sort the characters in the string. Some of the steps has been done for you. Fill out the program in C++. See below for the expected console output. Make the program as simple as possible. Use introductory Object-Oriented C++ programming. If all the requirements are met, then this will be upvoted. Do use the C++ Standard Library headers, do not use the C Standard...
PYTHON PLS 1) Create a function search_by_pos. This function only has one return statement. This function...
PYTHON PLS 1) Create a function search_by_pos. This function only has one return statement. This function returns a set statement that finds out the same position and same or higher skill number. This function searches the dictionary and returns the same position and same or higher skill level. The function output the set statements that include the position only. For example input : dict = {'Fiora': {'Top': 1, 'Mid': 4, 'Bottom': 3},'Olaf': {'Top': 3, 'Mid': 2, 'Support': 4},'Yasuo': {'Mid': 2,...
-> > Use recursion to write a C++ function for determining if a strings has more...
-> > Use recursion to write a C++ function for determining if a strings has more vowels than consonants. Please include the pseudo code so that I can understand better with simple English as much as possible.
Only Program in C for this. No other programming language is allowed. Using a function, we...
Only Program in C for this. No other programming language is allowed. Using a function, we will add a range of values of an array. The range is going to be determined by the user. In this example, if you put the following array down as: 1.5 -5.6 8.9 4.6 7.8 995.1 45.1 -5964.2 … and the user tells you to add from the 3rd element to the 6th element, your program is going to need to add the values:...
in 800 words create a SWOT analysis focusing only on the strength and weaknesses portion and...
in 800 words create a SWOT analysis focusing only on the strength and weaknesses portion and share ZMG's financial situation
Python Create a move function that is only defined in the base class called Objects. The...
Python Create a move function that is only defined in the base class called Objects. The move function will take two parameters x,y and will also return the updated x,y parameters.
Create a Deterministic finite automaton that takes in binary strings and accepts them which has both...
Create a Deterministic finite automaton that takes in binary strings and accepts them which has both an odd number of zeros and a sum that is divisible by 3 (but no others). For example, 0111 should be accepted, but not 011 or 111.
QUESTION 1 : Words: 200 Create a template for a report on any organization function :...
QUESTION 1 : Words: 200 Create a template for a report on any organization function : Marketing Human resource Management Operation management Financial
Main Objective: Create a function collect_statistics to count the number of words and mean length of...
Main Objective: Create a function collect_statistics to count the number of words and mean length of words in each sentence This is my code so far but I am struggling to join the two functions together. I would appreciate the help! The sentence given as an example is : "Haven't you eaten 8 oranges today?" the mean length of this sentence is 4.5 for reference. Each sentence needs to be split up if given multiple sentences, assuming each sentence ends...
A parser has to translate OUR words and symbols into tokens, why is this?  in other words...
A parser has to translate OUR words and symbols into tokens, why is this?  in other words why can't the machine just do what we write?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT