#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<set>
#include<map>
#define db(a) \
cout << #a << " = " << a << endl
#define db2(a, b) \
cout << #a << " = " << a << " " << #b << " = " << b << endl
#define inf (1<<30)
#define foreach(m, it) \
for (typeof(m.begin()) it = m.begin(); it != m.end(); it++)
using namespace std;
int n;
bool espali(string linea) {
int n = linea.size();
for (int i = 0; i < n / 2; i++) {
if (linea[i] != linea[n - i - 1])
return false;
}
return true;
}
int main() {
#ifdef dennisbot
freopen("in.in", "r", stdin);
freopen("ou.out", "w", stdout);
#endif
char linea[100];
set<string> s;
while (gets(linea) != NULL) {
int n = strlen(linea);
s.clear();
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
string aux = string(linea).substr(i, j - i + 1);
if (espali(aux))
s.insert(aux);
}
}
printf("The string '%s' contains %d palindromes.\n", linea , s.size());
}
return 0;
}
Here is the Statementviernes, 13 de julio de 2012
353 - Pesky Palindromes, uva
Suscribirse a:
Enviar comentarios (Atom)
No hay comentarios:
Publicar un comentario