Maximum occurrence : HackerEarth Problem Solution

You are given a string which comprises of lower case alphabets (a-z), upper case alphabets (A-Z), numbers, (0-9) and special characters like !,-.; etc.



You are supposed to find out which character occurs the maximum number of times and the number of its occurrence, in the given string. If two characters occur equal number of times, you have to output the character with the lower ASCII value.


For example, if your string was: aaaaAAAA, your output would be: A 4, because A has lower ASCII value than a.


Input format:

The input will contain a string.

Output format:

You've to output two things which will be separated by a space:
i) The character which occurs the maximum number of times.
ii) The number of its occurrence.

Constraints:

The maximum length of the string can be 1000.

SAMPLE INPUT


Pulkit is a dog!!!!!!!!!!!!


SAMPLE OUTPUT


! 12


Implementation:


#include <stdio.h>
#define MAX 1000000
int main()
{
     char *s;
     int i;
     int hash[MAX];
     int max_val=0;
     char max_char='\0';
     s = (char*)malloc(sizeof(char)*MAX);
     gets(s);
     i=0;
     memset(hash,0,sizeof(hash));
     while(*(s+i))
     {
          hash[*(s+i)]++;
          if(hash[*(s+i)]==max_val)
          {
               if(*(s+i)<max_char)
               {
                    max_char = *(s+i);
               }
          }
          if(hash[*(s+i)]>max_val)
          {
               max_val = hash[*(s+i)];
               max_char = *(s+i);
          }
          i++;
     }
     printf("%c %d",max_char,max_val);
     return 0;
}