Skip to content

Instantly share code, notes, and snippets.

@mura303
Created February 27, 2013 14:50
Show Gist options
  • Save mura303/5048437 to your computer and use it in GitHub Desktop.
Save mura303/5048437 to your computer and use it in GitHub Desktop.
// http://community.topcoder.com/stat?c=problem_statement&pm=11889
#include <iostream>
#include <cstring>
using namespace std;
// |aaa|b|c|d|e|
int doit( const char* str )
{
int count = 0;
int len = strlen(str);
for( int p1=1; p1<len; p1++ ){
for( int p2=p1+1; p2<len; p2++ ){
for( int p3=p2+1; p3<len; p3++ ){
for( int p4=p3+1; p4<len; p4++ ){
char s1[256], s2[256];
strncpy( s1, &str[p1], p2-p1 );
s1[p2-p1]='\0';
strncpy( s2, &str[p3], p4-p3 );
s2[p4-p3]='\0';
if( strcmp( s1, s2 ) == 0 ){
// cout << s1 << ":" << s2 << endl;
count++;
}
}
}
}
}
return count;
}
int main()
{
cout << doit( "topcoderdivtwo" ) << endl;
cout << doit( "foxciel" ) << endl;
cout << doit( "magicalgirl" ) << endl;
cout << doit( "waaiusushioakariusushiodaisuki" ) << endl;
cout << doit( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ) << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment