Pawri Meme Problem Code: PAWRISubmit
Read problems statements in Mandarin Chinese, Russian, Vietnamese, and Bengali as well.
Lately, Chef has been inspired by the "pawri" meme. Therefore, he decided to take a string 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 denoting the number of test cases. The description of test cases follows.
- The first and only line of each test case contains a single string .
Output
For each test case, print a single line containing the string after it is modified by Chef.
Constraints
- 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 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