Pawri Meme Solution

 

Problem

On the occasion of his birthday, Chef has decided to throw a grand party at Babloo Resort. Chef is a huge fan of the popular "pawri" trend on Instagram. So, he decided to modify the invitation card represented by a string S, by changing each of the substrings that spell "party" to "pawri". Determine the resulting string.

Input Format

  • 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 Format

For each test case, print a single line containing the modified string.

Constraints

  • 1 \leq T \leq 10
  • 1 \leq |S| \leq 10^5
  • S contains only lowercase English letters

Sample 1:

Input
Output
3
partyallnightpartyallnight
babloo
yehamaripartyhorahihai
pawriallnightpawriallnight
babloo
yehamaripawrihorahihai

Explanation:

Test Case 1: There are two occurrences of "party" in the string. Replace each one of them with "pawri".

Test Case 2: The string has no occurrences of the word "party".





Program :


/* package codechef; // don't place package name! */


import java.util.*;

import java.lang.*;

import java.io.*;


/* Name of the class has to be "Main" only if the class is public. */

class Codechef

{

public static void main (String[] args) throws java.lang.Exception

{

// your code goes here

Scanner sr=new Scanner(System.in);

int t=sr.nextInt();

while(t-->0)

{

    String a=sr.next();

  //  StringBuilder sb=new StringBuilder(s);

    if(a.contains("party"))

    a=a.replaceAll("party","pawri"); 

    System.out.println(a);

}

}

}


Post a Comment

0 Comments