#include<iostream>
#include<string>
#include<climits>
using namespace std;
int freq[256]={0};
int main(){
char a[1000];
int i=0;
int maxi=0;
int idx=-1;
a[i]=cin.get();
freq[int(a[i])]++;
if (freq[int(a[i])]>maxi)
{
maxi=freq[int(a[i])];
idx=int(a[i]);
}
while (a[i]!='\n')
{
i++;
a[i]=cin.get();
freq[int(a[i])]++;
if (freq[int(a[i])]>maxi)
{
maxi=freq[int(a[i])];
idx=int(a[i]);
}
}
cout<<char(idx);
return 0;
}
Run error on submission
hello @sagar_aggarwal
that while loop condition is not true .
\n will there only if we there is more than one line.
we have single line only.
istead of using cin.get to read each char one by one .
read all strings at once by cin>>a;
and then apply ur logic
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.