-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrings.cpp
More file actions
46 lines (42 loc) · 929 Bytes
/
Strings.cpp
File metadata and controls
46 lines (42 loc) · 929 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
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string text = "FEHKEKTGJHG";
// Converting uppercase to lowercase
for (int i = 0; i < text.length(); i++)
{
text[i] += 32;
}
cout << "LOWERCASE : " << text << endl;
// Converting lowercase to uppercase
for (int i = 0; i < text.length(); i++)
{
text[i] -= 32;
}
cout << "UPPERCASE : " << text << endl;
// To find the repeating letter in a string
int freq[26];
int maxfreq = -19999;
char ans;
for (int i = 0; i < 26; i++)
{
freq[i] = 0;
}
for (int i = 0; i < text.length(); i++)
{
freq[text[i] - 'a']++;
}
for (int i = 0; i < 26; i++)
{
if (maxfreq < freq[i])
{
maxfreq = freq[i];
ans = i + 'a';
}
}
cout << maxfreq << " " << ans << endl;
return 0;
}