Skip to content

Instantly share code, notes, and snippets.

@McSinyx
Last active July 24, 2016 03:07
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 McSinyx/9a57ae28fb762feb0e5dadad29ba8ec9 to your computer and use it in GitHub Desktop.
Save McSinyx/9a57ae28fb762feb0e5dadad29ba8ec9 to your computer and use it in GitHub Desktop.
FINDTEXT - NTUcoder problem 5548
/*
* Trò chơi tìm chữ 3 <http://laptrinh.ntu.edu.vn/Problem/Details/5548>
*
* Copyright (C) 2016 Raphael McSinyx
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char *x = malloc(10000000);
scanf("%s", x);
long len = strlen(x) / 2 + 1, i, idx = 0;
char *dup;
char *s = malloc(len);
for (i = 1; i < len; i++) {
s[i - 1] = x[i - 1];
s[i] = 0;
dup = strstr(x + i, s);
if (dup == NULL)
break;
else
idx = dup - x;
}
printf("%ld %ld\n", i - 1, idx + 1);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment