Skip to content

Instantly share code, notes, and snippets.

@SudhagarS
Created October 30, 2012 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SudhagarS/3982372 to your computer and use it in GitHub Desktop.
Save SudhagarS/3982372 to your computer and use it in GitHub Desktop.
class StrSimilar{
public static void main(String[] args) {
java.util.Scanner sc=new java.util.Scanner(System.in);
int N=sc.nextInt(),sol;
while(N--!=0){
sol=0;
char[] s=sc.next().toCharArray();
for(int i=0;i<s.length;i++){
for(int j=i;j<s.length;j++){
if(s[j]==s[j-i]) sol++;
else break;
}
}
System.out.println(sol);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment