-
Notifications
You must be signed in to change notification settings - Fork 0
/
problema_36.cpp
54 lines (39 loc) · 857 Bytes
/
problema_36.cpp
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
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
fstream f("cuvinte.txt", ios::in);
void citire_cuvant(char* cuv)
{
f >> cuv;
f.get();
}
bool palindrom(char* cuv)
{
char temp_cuv[21];
strcpy(temp_cuv, cuv);
unsigned int t = strlen(temp_cuv);
for (int i = 0; i < t; i++) temp_cuv[i] = (char) toupper(temp_cuv[i]);
for (int i = 0; i < t / 2; i++)
if (temp_cuv[i] != temp_cuv[t - i - 1]) return false;
return true;
}
int main()
{
unsigned int n;
char cuv[21];
bool exista = false;
f >> n; f.get();
for (unsigned int i = 0; i < n; i++)
{
citire_cuvant(cuv);
if (palindrom(cuv))
{
cout << cuv << ' ';
exista = true;
}
}
if (!exista) cout << "Nu exista";
f.close();
return 0;
}