My issue
can anyone please explain the logic for the question like how to approach??
My code
/* 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
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
String S=sc.nextLine();
int n=S.length();
int count=0;
for (int j=1;j<n;j++)
{
for (int k=j+1;k<n;k++)
{
String P = S.substring(0, j);
String Q = S.substring(j, k);
String R = S.substring(k);
if (P+Q+R==S && P+R==Q)
count++;
}
}
System.out.println(count);
}
}
}
Problem Link: Break The String Practice Coding Problem