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 , 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 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 Format
For each test case, print a single line containing the modified string.
Constraints
- contains only lowercase English letters
Sample 1:
3 partyallnightpartyallnight babloo yehamaripartyhorahihai
pawriallnightpawriallnight babloo yehamaripawrihorahihai
Explanation:
Test Case : There are two occurrences of "party" in the string. Replace each one of them with "pawri".
Test Case : 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);
}
}
}
0 Comments