-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchar arrayincpp.cpp
76 lines (71 loc) · 1.2 KB
/
char arrayincpp.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
#include <iostream>
#include <array>
#include <vector>
#include <string>
using namespace std;
int main(){
//input in array and output
/*char name[20];
cin>>name;
cout<<name<<endl;;
int count=0;
for(auto i:name){
if(i=='\0'){
break;
}
else{
count++;
}
}
cout<<"length of string is "<<count<<endl;
*/
// reversing a string
/*char name[20];
cin>>name;
int l=0;
int count=0;
for(auto j:name){
if(j=='\0'){
break;
}
else{
count++;
}
}
int r=count-1;
while(l<r){
swap(name[l],name[r]);
l++;
r--;
}
cout<<name<<endl;
*/
// max number of char in string
string name;
getline(cin,name);
int arr[26]={0};
for (size_t i = 0; i <name.length() ; i++)
{char ch=name[i];
int number=0;
if(ch>='a'&&ch<='z'){
number=ch-'a';
}
else{
number=ch-'A';
}
arr[number]++;
}
int maxindex=0;
int maxval=0;
for (size_t i = 0; i < 26; i++)
{
if (arr[i]>maxval)
{
maxindex=i;
maxval=arr[i];
}
}
char final='a'+maxindex;
cout<<final<<endl;
return 0;
}