Created
February 27, 2013 14:50
-
-
Save mura303/5048437 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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