#include<bits/stdc++.h>
#include<cstring>
#define arraySize 10
using namespace std;
char returnMaxOccur(char *str);
int main()
{
char str[]="teet";
cout<<"The max occuring character is"<<" "<<returnMaxOccur(str)<<endl;
return 0;
}
char returnMaxOccur(char* str)
{
int high=-1;
char t;
int counter[arraySize]={0};
int len=strlen(str);
for(int i=0;i<len;i++)
{
counter[str[i]]++;
}
for(int i=0;i<len;i++)
{
if(high<counter[str[i]])
{
high=counter[str[i]];
t=str[i];
}
}
return t;
}
In the following question when #include<bits/stdc++.h>
is included the results for input string are as follows,
1)teet: ans is t
2)eett: ans is e
3)ttee: ans is t
4)ette: ans is e
but when i include #include<iostream>
instead of #include<bits/stdc++.h>
the results are
1)teet: ans is e
2)eett: ans is t
3)ttee: ans is t
4)ette: ans is e
what is the reason for this behaviour,or am i doing anything wrong?