█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 2060

Problema 0x43 - Encontrar el borde más largo de una string

  • Autor: Javier
  • Fecha: 2020-11-20 23:16:17 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.009 s 1 KBi
#2
Correcto
0.007 s 1 KBi
#3
Correcto
0.006 s 1 KBi
#4
Correcto
0.007 s 1 KBi
#5
Correcto
0.007 s 6 KBi
#6
Correcto
0.007 s 6 KBi
#7
Tiempo límite excedido
1.004 s 1 KBi
#8
Tiempo límite excedido
1.04 s 1 KBi
#9
Tiempo límite excedido
1.028 s 1 KBi
#10
Tiempo límite excedido
1.042 s 1 KBi
#11
Tiempo límite excedido
1.023 s 1 KBi
#12
Tiempo límite excedido
1.006 s 1 KBi
#13
Tiempo límite excedido
0.738 s 1 KBi
#14
Tiempo límite excedido
1.035 s 2 KBi
#15
Tiempo límite excedido
1.035 s 1 KBi
#16
Tiempo límite excedido
1.056 s 1 KBi
#17
Tiempo límite excedido
1.075 s 2 KBi
#18
Tiempo límite excedido
1.036 s 1 KBi
#19
Tiempo límite excedido
1.028 s 2 KBi
#20
Tiempo límite excedido
0.9 s 1 KBi
#21
Tiempo límite excedido
0.91 s 1 KBi
#22
Tiempo límite excedido
0.933 s 1 KBi
Puntos totales: 28 / 100

Código

#include <iostream>
#include <string>

using namespace std;

bool endsWith(string const &str, string const &ending) {
    if (str.length() >= ending.length()) {
        return str.compare(
				 str.length() - ending.length(),
				 ending.length(),
				 ending) == 0;
    } else {
        return false;
    }
}

int main() {
  string input;
  cin >> input;
  int max_border = 0;
  for (int i = 1; i < input.length(); i++) {
	 string border = input.substr(0, i);
	 if(endsWith(input, border)) {
		max_border = border.length();
	 }
  }
  cout << max_border << endl;
  return 0;
}