-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDSA_22_Character_Array_Strings.cpp
More file actions
79 lines (79 loc) · 1.64 KB
/
Copy pathDSA_22_Character_Array_Strings.cpp
File metadata and controls
79 lines (79 loc) · 1.64 KB
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
#include<iostream>
using namespace std;
char tolowercase(char ch){
if(ch>='a' && ch<='z'){
return ch;
}
else{
char temp=ch-'A'+'a';
return temp;
}
}
bool checkpalindrome(char a[],int n){
int s=0;
int e=n-1;
while(s<=e){
if(a[s]!=a[e]){
return 0;
}
else {
s++;
e--;
}
}
return 1;
}
void reverse(char name[],int n){
int s=0;
int e=n-1;
while(s<e){
swap(name[s++],name[e--]);
}
}
int getlength(char name[]){
int count=0;
for(int i=0;name[i]!='\0';i++){
count++;
}
return count;
}
char getmaxoccurence(string s){
int arr[26]={0};
for(int i=0;i<s.length();i++){
char ch=s[i];
int number=0;
if(ch>='a' && ch<='z'){
number=ch-'a';
}
else{
number=ch-'A';
}
arr[number]++;
}
int maxi=-1,ans=0;
for(int i=0;i<26;i++){
if(maxi<arr[i]){
ans=i;
maxi=arr[i];
}
}
char finalanswer='a'+ans;
return finalanswer;
}
int main(){
// char name[20];
// cout<<"Enter Your Name: ";
// cin>>name;
// cout<<"Namastey Duniya \nYour Name is :"<<name<<endl;
// int len=getlength(name);
// cout<<"Length : "<<len<<endl;
// // reverse(name,6);
// // cout<<"Namastey Duniya \nYour Name is :"<<name<<endl;
// cout<<"Palindrome or not "<<checkpalindrome(name,len);
// cout<<"CHARACTER is "<<tolowercase('b')<<endl;
// cout<<"CHARACTER is "<<tolowercase('C')<<endl;
string s;
cin>>s;
cout<<getmaxoccurence(s);
return 0;
}