Need some help
Mar 19, 2016 at 2:19pm UTC
Could somebody make the function which will do following:
First parameter(argument) is string ,second parameter is vector which containts list of phrases which need to be puted into ( ).
example:
http://prnt.sc/ah8bjz
this is what I had in mind:
using namespace std;
string Function(string s, vector<string>v)
{
string s1;
for (int i=0;i<v.size();i++)
{ for(int j=0;j<s.size();j++)
{string s1=s.substr(j,v[i].size());
if(s1==v[i])
{
s=s.substr(0,j)+"("+v[i]+")" + s.substr(j+v[i].size(),s.size()-(v.size()+j));
}
}
}
return s;
}
but doesn't workk
Mar 19, 2016 at 2:29pm UTC
I just made it a bit more readable.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
using namespace std;
string Function(string s, vector<string>v)
{
string s1;
for (int i = 0; i < v.size(); i++)
{ for (int j= 0; j < s.size(); j++)
{string s1 = s.substr(j, v[i].size());
if (s1 == v[i])
{
s = s.substr(0,j) + "(" +v[i] + ")" + s.substr(j + v[i].size(), s.size() - (v.size() + j));
}
}
}
return s;
}
Last edited on Mar 19, 2016 at 2:35pm UTC
Topic archived. No new replies allowed.