UVA 11577 - Letter Frequency







#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s,w;
    int i,j,a[256],n,k,m,l,p,c;
    //freopen("1577.txt","r",stdin);
    //freopen("1577out.txt","w",stdout);
    cin>>n;
    cin.ignore();
    for(i=1;i<=n;i++)
    {
        getline(cin,s);
        w="";
        for(c=0;c<s.length();c++)
        {
            w+=tolower(s[c]);
        }
        m=0;
        for(j=0;j<256;j++)
        {
            a[j]=0;
        }
        for(k=0;k<w.length();k++)
        {
            if(w[k]!=' ')
            {
                a[w[k]]++;
                m=max(a[w[k]],m);

            }


        }
        for(l=0;l<256;l++)
        {
           if(a[l]==m)
           {
               printf("%c",l);
           }
        }
        cout<<endl;



    }
    return 0;

}

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment