Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <algorithm>
- #include <cstring>
- #include <string>
- #include <cctype>
- #include <stack>
- #include <queue>
- #include <list>
- #include <vector>
- #include <map>
- #include <set>
- #include <sstream>
- #include <stdlib.h>
- #include <cmath>
- #define FOR(i,A) for(typeof (A).begin() i = (A).begin() ; i != (A).end() ; i++)
- #define mp make_pair
- #define debug( x ) cout << #x << " = " << x << endl
- #define clr(v,x) memset( v, x , sizeof v )
- #define all(x) (x).begin() , (x).end()
- #define rall(x) (x).rbegin() , (x).rend()
- #define TAM 110
- using namespace std;
- typedef pair<int,int> ii ;
- typedef long long ll ;
- typedef long double ld ;
- typedef pair<int,ii> pii ;
- string cad;
- set<string>mySet;
- bool isPalindrome(string str){
- string tmp = str;
- reverse(tmp.begin(),tmp.end());
- if(str == tmp)
- return true;
- return false;
- }
- void generateCombination(int strWord, int index){
- string strTmp = ""; //cout<<index<<endl;
- for(int x=index; x<cad.size(); x++)
- {
- strTmp += cad[x];
- if(strTmp.size() == strWord)
- {
- if(isPalindrome(strTmp))
- mySet.insert(strTmp);
- strTmp = "";
- if(index<cad.size()-1)
- generateCombination(strWord,++index);
- return;
- }
- if(index == cad.size()-1 || x == cad.size()-1)
- return;
- }
- }
- void getLetter(){
- string letter = "";
- for(int x=0; x<cad.size(); x++)
- {
- letter += cad[x];
- mySet.insert(letter);
- letter = "";
- }
- }
- int main(){
- int wordSize;
- int initPos;
- while(cin>>cad){
- if(cad.size() == 1)
- printf("The string \'%s\' contains 1 palindromes.\n",cad.c_str());
- else{
- wordSize = 2;
- initPos = 0; while(wordSize<=cad.size()){
- generateCombination(wordSize, initPos);
- wordSize++;
- }
- getLetter();
- printf("The string \'%s\' contains %d palindromes.\n",cad.c_str(), mySet.size());
- mySet.clear();
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement