/* The following program replaces every occurance 
 of string s2 in string s1 by string s3. We'll 
 assume here that s2 is not a substring of s3. 
 Also, we'll ignore case.
*/
#include <iostream>
#include <string>
using namespace std;
string toupper(string s);
int main()
{
	int n2, i, pos, count = 0;
	string s1, s2, s3, t1, t2, t3;
	cout << "Enter a string: " << endl;
	getline(cin,s1);
	cout << "Enter a string to be replaces: " << endl;
	cin >> s2;
	t2 = toupper(s2);
	cout << "Enter a string to replace the previous one: " << endl;
	cin >> s3;
	// We'll replace every occurance of s2 in s1 by s3.
	n2 = s2.size();
	i = 0;
	while (i < s1.size()) // Note the size of s1 may keep changing
	{
		t1 = toupper(s1);
		pos = t1.find(t2);
		if (pos >= 0 && pos < s1.size())
		{
			s1.replace(pos,n2,s3);
			//count++;
		}
		i++;
	}
	//cout << count << endl;
	cout << s1 << endl;
	return 0;
}

string toupper(string s)
{
	int i, n = s.size();
	for (i = 0; i < n; i++)
		s[i] = toupper(s[i]);
	return s;
}
