// подключение библиотек
#include "stdafx.h"
#include <iostream>
using namespace std;
// оглашение переменных
char s[100];
char scopy[100];
char word[100][100],w[25];
int n;
//===функция ввода===
void input()
{
cout<<"Input array"<<endl;
gets(s); // ввод массива
cout<<"Enter array :"<<endl;
puts(s); // вывод массива
}
//===функция поиска слов===
void solution()
{
strcpy(scopy,s);
char *ptr; // указатель на искаемую лексему
char *delimiter="., _!?:; \0"; // лексемы
int i=0;
ptr = strtok(scopy,delimiter); // первое слово рядка
while(ptr!=NULL) // поиск слов
{
strcpy(word[i],ptr); // занесение слов в массив
i++;
ptr = strtok(NULL,delimiter); // следующее слово
}
n=i;
}
//===поиск слов палиндромов===
bool words(char scopy[100])
{
size_t x(0), i, len(strlen(s) - 1), slen(len >> 1);
for(i = 0; i < slen; ++i)
if(s[i] != s[len - i])
return false;
return true;
}
void longword()
{
int max = strlen(word[0]);
strcpy(w,word[0]);
for(int i=0;i<n;i++)
{
if (max<strlen(word[i]))
{
max=strlen(word[i]);
strcpy(w,word[i]);
}
cout<<"Word = "<<w<<" length = "<<max<<endl;
}
}
//===функция вывода===
void output()
{
cout<<"========================="<<endl;
for(int i=0;i<n;i++)
{
puts(word[i]);
}
cout<<"Number of words"<<n<<endl;
}
//===главная функция===
int main()
{
input();
solution();
words(scopy);
longword();
output();
system("pause");
}