An array of lines of characters each You want to display only those li

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
An array of M lines of N characters each.
You want to display only those lines that are palindromic, ie reads the same from left to right and right to left.
When checking the line is necessary to determine its length using the strlen () (#include)
Roman Kozar - Copyright, 2015
Variant 10
*/
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
//function of giving the array
char** setArray( int numberStrings, int numberElements ) {
char **array;
array = ( char ** ) malloc( numberStrings*sizeof( char * ) );
for( int count = 0; count < numberStrings; count++ )
array[ count ] = ( char * ) malloc( numberElements*sizeof( char ) );
for( count = 0; count != numberStrings; count++ ) {
cin >> array[ count ];
}
return array;
}
//function, which solute palindroms
void findPalindroms( char** array, int numberStrings ) {
int sizeArray;
bool flag;
for( int count = 0; count != numberStrings; count++ ) {
sizeArray = strlen( array[ count ] ) - 1;
flag = true;
for( int indicator = 0; indicator != sizeArray; indicator++ ) {
if( array[ count ][ indicator ] != array[ count ][ sizeArray ] )
flag = false;
sizeArray--;
}
if( flag )
cout << array[ count ] << " ";
}
}
//function of clearing the array
void freeArr( char **array, int deleteElements ) {
int count = 0;
for ( count = 0; count < deleteElements; ++count ) {
free( array[ count ] );
}
free(array);
}
//main function, contains three other functions
int main() {
cout << "Input the size of array: ";
short numberStrings, numberElements;
cin >> numberStrings >> numberElements;
char** array;
array = setArray( numberStrings, numberElements );
findPalindroms( array, numberStrings );
freeArr( array, numberElements );
}