Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- #define SIZE 100000
- int main(void)
- {
- char s[SIZE] = {0};
- gets(s);
- clock_t start = clock();
- char subs[SIZE] = "-1\0";
- int cb = 0, ce = 0;
- int ab = 0, ae = 0;
- for (int i = 0; /*i < SIZE && */ s[i]; ++i){
- cb = i;
- ce = i;
- for (int j = i+1; /*j < SIZE* &&*/ s[j]; ++j)
- {
- if (s[i] == s[j]){
- for (int k = ((j-i)/2)-1; k > 0 /*(j-i)/2*/; k /= 2){
- if ( s[i+k] != s[j-k]){
- ce = j;
- }
- }
- }
- else{
- ce = j;
- }
- }
- long al = ae - ab, cl = ce - cb;
- if ( al < cl)
- {
- ae = ce;
- ab = cb;
- continue;
- }
- if (al == cl )
- {
- int i1 = ab, i2 = cb;
- for (; i1 <= ae, i2 <= ce; ++i1, ++i2){
- if (s[i1] < s[i2])
- goto notless;
- if (s[i1] > s[i2])
- break;
- }
- ae = ce;
- ab = cb;
- notless:
- continue;
- }
- }
- if ((ae-ab) > 0){
- for (int i = ab ; i <= ae; ++i)
- subs[i-ab] = s[i];
- subs[ae-ab+1] = 0;
- }
- double t = (double)((clock() - start) / CLOCKS_PER_SEC) ;
- printf("%s\n%lf",subs, t);
- fflush(stdin);
- getc(stdin);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement