Question: In c++ #include #include #include #include using namespace std; int main() { int pl,cnt,i,j; string s=alpha beta beta gamma gamma gamma delta delta delta delta

In c++

#include

#include

#include

#include

using namespace std;

int main()

{

int pl,cnt,i,j;

string s="alpha beta beta gamma gamma gamma delta delta delta delta epsilon epsilon epsilon zeta zeta zeta zeta zeta zeta zeta zeta";

map mp; //map to store string and count

vectorresult; // vector to word of string

istringstream iss(s); // stream object

for(string str;iss>>str;) //read each word in string

result.push_back(str); //insert word to vector

cout<<" Enter Maximum length : "; // enter max length

cin>>pl;

for(i=0;i

{

string phrase;

for(j=i,cnt=0;j

{

phrase=phrase+" "+result[j];

}

if(cnt==pl)

{

if(mp.find(phrase)!=mp.end()) //if max string already in map, just increase count

mp[phrase]++;

else

mp[phrase]=1; // if string not in map, set count as 1

}

}

//iterate through map and print string of maxsize pl and its count

for(map:: iterator i=mp.begin();i!=mp.end();i++)

{

cout<first<<" "<second<

}

return 0;

}//end of main

this code takes the string and outputs

alpha beta 1

beta beta 1

beta gamma 1

delta delta 3

delta epsilon 1

epsilon epsilon 2

epsilon zeta 1

gamma delta 1

gamma gamma 2

zeta zeta 7

Now i want to input the string for a length of 1 (variable pl) "zeta beta alpha"

this code would print out

zeta 1

beta 1

alpha 1

counting the string of length one, but instead of printing that out i want it to print " all strings have the same frequency" meaning if the value of the map is the same print " all strings have the same frequency"

so instead of printing for example

zeta zeta 2

beta beta 2

alpha alpha 2

it would print " all strings have the same frequency"

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!