forked from Mustafa-Hassan2001/DSA-Course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday2.cpp
53 lines (42 loc) · 1.05 KB
/
day2.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
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//maximum occurring string
//Function to find the maximum occurring character in a string.
char getMaxOccuringChar(string s){
int arr[26] = {0};
for(int i=0; i<s.length(); i++){
char ch = s[i];
int num = 0;
num = ch - 'a';
arr[num]++;
}
int max = -1, ans=0;
for(int i=0; i<26; i++){
if(max < arr[i]){
ans=i;
max = arr[i];
}
}
return 'a' + ans;
}
//replace space
string replaceSpace(string str){
string temp = " ";
for(int i=0; i< str.length(); i++){
if(str[i] == ' '){
temp.push_back('@');
temp.push_back('4');
temp.push_back('0');
}
else{
temp.push_back(str[i]);
}
}
return temp;
}
int main(){
cout<<getMaxOccuringChar("test");
cout<<replaceSpace("My name is khan");
return 0;
}