Skip to content

Instantly share code, notes, and snippets.

@LifeMoroz
Created November 18, 2012 16:17
Show Gist options
  • Save LifeMoroz/4106061 to your computer and use it in GitHub Desktop.
Save LifeMoroz/4106061 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <conio.h>
using namespace std;
bool cmp(char s[60],char s1[60], int count)
{
for (int i=0;i<count;i++)
if (s[i]!=s1[i]) return 0;
return 1;
}
void polidrom(char s[60], int count)
{
int x=0;
for(int i=0; i < count;i++)
{
if(s[count-1-i]!=s[i])
break;
else x=1;
}
if(x)
{
for(int i=0; i < count;i++)
{
cout<<s[i];
}
cout<<' ';
}
}
int main()
{
char words[100];
char **massive=new char*[100];
int j=0;
int i=0;
int countLast;
int counter[100];
do
{
words[i]=getch();
if(((words[i]<'a') || (words[i]>'z')) && (words[i]!=' ') && (words[i]!='.'))
{
cout << char('\a');
continue;
}
//cout << word[i];
if (words[i]=='.')
{
massive[j]=new char[i];
for (int g=0; g<i; g++)
massive[j][g]=words[g];
/*for(int count=0; count < i;count++)
{
cout<<massive[j][count];
} */
countLast=i;
}
if (words[i]==' ')
{
massive[j]=new char[i];
for (int g=0; g<i; g++)
massive[j][g]=words[g];
/*for(int count=0; count < i;count++)
{
cout<<massive[j][count];
} */
counter[j]=i;
i=-1;
j++;
}
i++;
}
while (words[i-1]!='.');
for (i=0;i<j;i++)
{
if (counter[i]==countLast)
if (cmp(massive[i],massive[j],countLast))
continue;
polidrom(massive[i], counter[i]);
}
system("pause");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment