hey guys im working on a homework problem which requires two things
-count the total number of clumps
-determine the longest clump
i finally made my code to recognize the number of total clumps however i still cnt figure out how to determine the longest clump
any help be great!thanks:)
#include <iostream>
#include <string>
using namespace std;
int countClumps(int k, string s, string & longest);
int main ()
{
string s, string2;
int length;
char play;
do
{
cout << "Enter a minmum clump length of 2 or more: ";
cin >> length;
while (length <= 1)
{
cout << "ILLEGAL VALUE!!!!" << endl;
cout << "Please Enter a minmum clump length of 2 or more:";
cin >> length;
}
cout << "Enter one or more words each having at least ";
cout << "2 characters. When you want to quit, enter any word with fewer than 2 characters." << endl;
cin >> s;
cout << countClumps(length, s, string2) << endl;
cout << "string2 is" << string2 << endl;
cout << "play again";
cin >> play;
}
while (play != 'n');
return 0;
}
int countClumps(int k, string s, string & longest)
{
longest = "";
// cout<<"long is" <<longest<<endl;
int i = 1, g = 0, total = 0;
while (g < s.length())
{
while (i < s.length() && s[g] == s[i])
{
i++;
}
int y = i - g;
int p = g;
if (y >= k)
total++;
if (y > longest.length())
{
longest = s[g], s[y];
}
g = i;
}
return total;
//cout <<s<<"has " << total << " clumps." << endl;
}