-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask 2 (1).cpp
More file actions
47 lines (42 loc) · 808 Bytes
/
task 2 (1).cpp
File metadata and controls
47 lines (42 loc) · 808 Bytes
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
#include <iostream>
#include <cstring>
using namespace std;
int countRepeatedLetters(char *word){
int len = strlen(word);
char count ;
int repeat = 0;
for(int i = 0; i < len; i++){
int count= 1;
for(int j = i+1; j< len; j++){
if(word[i] == word[j])
{
count++;
}
if(count > repeat)
repeat = count;
}
}
return repeat;
}
int main()
{
string str;
cout<<"Enter the string";
getline(cin, str);
int res;
char arr[100];
strcpy(arr, str.c_str());
int maxRepeat = 0;
string maxword;
char *word = strtok(arr, " ");
while (word != NULL){
res = countRepeatedLetters(word);
if(res > maxRepeat){
maxRepeat = res;
maxword = word;
}
word = strtok(NULL, " ");
}
cout << "Word with highest repeats: " << maxRepeat<< endl;
return 0;
}