this the the link of instructions it starts page 25 https://drive.google.com/fil
ID: 3886144 • Letter: T
Question
this the the link of instructions it starts page 25
https://drive.google.com/file/d/0B54VYuzeA502cm5lNklsTmdoME0/view?usp=sharing
how can i fix this to get 100 percent. please rewrite the code or fix it
bool prefixAgain(const string& str, int n)
{
int len = str.length();bool prefixAgain(const string& str, int n)
{
int len = str.length();
string prefix = str.substr(0,n);
for(int i = n; n+i <= len; i++)
{
if(prefix == str.substr(i, i + n))
{
return true;
}
}
return false;
}
Explanation / Answer
bool prefixAgain(const string& str, int n)
{
int len = str.length();
string prefix = str.substr(0,n);
//cout<<prefix<<endl;
//cout<<str.substr(1,2)<<endl;
for(int i = n; n+i <= len; i++)
{
//cout<<i<<" "<<n<<endl;
//cout<<str.substr(i,n)<<endl;
if(prefix == str.substr(i,n))
{
return true;
}
}
return false;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.