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 function that will take a string containing only alphanumeric characters that are in lowercase...
Write a function that will take a string containing only alphanumeric characters that are in lowercase (if you think your logic requires you to use more than one argument, please go ahead). Your task is to see if the string becomes a palindrome if only one character is removed from anywhere in the string.
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.
Root is a trie that has characters for values. When traversed it spells words by formin...
Root is a trie that has characters for values. When traversed it spells words by formin strings. I'm trying to make findNode such that it will return the node at which we start collecting candidates for words that start with a specific prefix. How do I code this method traversing depth-first? my code: private static TreeNode<Character> findNode(TreeNode<Character> root, String prefix, int index){ Stack <TreeNode<Character>> s = new Stack<>(); s.push(root); for(TreeNode<Character> child : root.getChildren()){ while(index <= prefix.length()-1){ if(prefix.charAt(index) == child.getValue()){ index++;...
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT