Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Level 2 ( weight: 7 5 % ) Once the basic function haveSameLetters has been completed, you can use it to accomplish the task for
Level weight:
Once the basic function haveSameLetters has been completed, you can use it to accomplish the
task for Level To run Level you simply have to pass in something other than you could pass in
or you could simply pass in no commandline argument at all.
When the command line argument is not the code in main branches off to the else block.
This is where you need to place your code for Level We have already provided the first part: words
are read in from standard input, and they are stored one by one inside a vector we are using the
Standard Template Library vector class for C In the next part of the code, you need to access
the words inside the vector, and print out all groups of words that have exactly the same letters.
Groups of words should be separated by commas no spaces and each group should appear on a
new line.
For example, if our input is
sore cake rose leaf teal fear late
Then the output should be
sore,rose
teal,late
words should appear in the order in which they were entered into the vector.
If the input is
earth heart hater atom moat mother
then the output should be
earth,heart,hater
atom,moat
Note that there are several tests in Level and it carries mor
in this i got error please add expected ouput in that code
#include
#include
#include
bool haveSameLettersconst std::string& str const std::string& str
std::string sortedstr str;
std::string sortedstr str;
std::sortsortedstrbegin sortedstrend;
std::sortsortedstrbegin sortedstrend;
return sortedstr sortedstr;
int mainint argc, char argv
char end;
long which ;
which argc strtolargv &end, : ;
if which Level
std::string word word;
std::cin word;
std::cin word;
std::cout std::boolalpha haveSameLettersword word;
else Level
std::vector v;
std::string word;
while std::cin word
vpushbackword;
std::vector groups;
for sizet i ; i vsize; i
std::string group vi;
for sizet j i ; j vsize; j
if haveSameLettersvi vj
group vj;
verasevbegin j;
j;
groups.pushbackgroup;
for const auto& group : groups
std::cout group std::endl;
return ;
this is code and below is error
Input:
deeps speed
Expected output:
deeps,speed
Input:
star art rats
Expected output:
star,rats
Input:
star art rats tar
Expected output:
star,rats
art,tar
Input:
pig lag alp gal elk eke pal
Expected output:
lag,gal
alp,pal
Input:
pig lap lag alp gal elk eke pal
Expected output:
lap,alp,pal
lag,gal
Input:
meat
team
able
tame
bale
mate
lab
oh
ho
Expected output:
meat,team,tame,mate
able,bale
ohho
please solve this
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started