-
Notifications
You must be signed in to change notification settings - Fork 0
/
28_char_arr.cpp
80 lines (62 loc) · 1.45 KB
/
28_char_arr.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
79
80
#include <iostream>
using namespace std;
// palindrome words read same from both ends like racecar same from left and right
void palindrome()
{
int noOfLetters = 0;
cin >> noOfLetters;
char word[noOfLetters];
cin >> word;
for (int i = 0; i < noOfLetters / 2; i++)
{
if (word[i] != word[noOfLetters - i - 1])
{
cout << word << " is Not palindrome" << endl;
return;
}
}
cout << word << " is Palindrome" << endl;
}
// largest word in a sentence
void lar_word()
{
int sen_len = 0;
cin >> sen_len;
cin.ignore(); // to clear buffer
char sentence[sen_len];
cin.getline(sentence, sen_len);
int i = 0; // traversing index
int words = 0;
int max_len_word = 0;
int st = 0, en = 0;
while (1)
{
if (sentence[i] == ' ' || sentence[i] == '\0')
{
if(max_len_word<words){
max_len_word = words;
st = en;
}
words = 0;
en = i+1;
}
else
{
words++;
}
if (sentence[i] == '\0')
break;
i++;
}
cout << max_len_word << endl;
// cout<<st<<en<<endl;
for(int i = 0;i<=max_len_word;i++)
cout<<sentence[i+st];
cout<<endl;
}
int main()
{
// palindrome();
lar_word();
return 0;
}