A special site for solving fun programming problems and challenges, interested in computer science, programming, basics, data structure and algorithms

 


Pawri Meme Problem Code: PAWRI
Submit

Read problems statements in Mandarin ChineseRussianVietnamese, and Bengali as well.

Lately, Chef has been inspired by the "pawri" meme. Therefore, he decided to take a string S and change each of its substrings that spells "party" to "pawri". Find the resulting string.

Input

  • The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
  • The first and only line of each test case contains a single string S.

Output

For each test case, print a single line containing the string after it is modified by Chef.

Constraints

  • 1T10
  • 1|S|105
  • S contains only lowercase English letters

Sample Input 1 

3
part
partypartiparty
yemaihuyemericarhaiauryahapartyhorahihai

Sample Output 1 

part
pawripartipawri
yemaihuyemericarhaiauryahapawrihorahihai

Explanation

Example case 1: There is no substring "party" in the original string.

Example case 2: The original string has 2 substrings "party".

Example case 3: There is only a single substring "party" in the original string.


solution in c++

#include<iostream>
#include<string>
using namespace std;

class solution
{
public:
	void solve()
	{
		string s;
		cin >> s;
		for (int i = 0; i < s.length(); i++)
		{
			if (s[i] == 'p' && s[i+1] == 'a' && s[i+2] == 'r' && s[i+3] == 't' && s[i+4] == 'y')
			{
				s[i + 0] = 'p';
				s[i + 1] = 'a';
				s[i + 2] = 'w';
				s[i + 3] = 'r';
				s[i + 4] = 'i';
			}
		}
		cout << s << "\n";
	}
};
int main()
{
	solution ss;

	int t;
	cin >> t;
	while (t--)
    {
		ss.solve();
	}

	return 0;
}

No comments:

Post a Comment