-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgfg_basic_problems.cpp
78 lines (70 loc) · 1.13 KB
/
gfg_basic_problems.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "interface.h"
int my_string_len(char *str)
{
int i = 0;
while (str[i] != 0)
i++;
return i;
}
int basic_gfg_probs::polindrome_words_count_in_sentence(char *str)
{
int pCount = 0, k = 0, beg = 0;
char sub_string[10];
bool isPalindrom = true;
while(*str != 0)
{
isPalindrom = true;
if (*str == ' ')
{
int e = k -1;
while (beg <= e)
{
char a = sub_string[beg];
if (isupper(a))
a = tolower(a);
char b = sub_string[e];
if (isupper(b))
b = tolower(b);
if (a == b){
beg++;
e--;
}
else{
isPalindrom = false;
break;
}
}
if (isPalindrom == true)
pCount ++;
k = beg = 0;
}
else{
sub_string[k] = *str;
k++;
}
*str++;
}
//check for last word
int e = k -1;
while (beg <= e)
{
char a = sub_string[beg];
if (isupper(a))
a = tolower(a);
char b = sub_string[e];
if (isupper(b))
b = tolower(b);
if (a == b){
beg++;
e--;
}
else{
isPalindrom = false;
break;
}
}
if (isPalindrom == true)
pCount ++;
k = beg = 0;
return pCount;
}