UVA ONLINE JUDGE
(PROBLEM: 11577)
Problem link:
https://uva.onlinejudge.org/index.phpoption=com_onlinejudge&Itemid=8&page=show_problem&problem=2624
https://uva.onlinejudge.org/index.phpoption=com_onlinejudge&Itemid=8&page=show_problem&problem=2624
Solution::
#include<bits/stdc++.h>
using namespace std;
int freq[30],t;
int main()
{
char letter[30],a[210];
scanf("%d\n",&t);
while(t--)
{ gets(a);
int len=strlen(a);
for(int i=0;i<26;i++)
{
letter[i]=i+97;
}
for(int i=0;i<len;i++)
{
a[i]=tolower(a[i]);
for(int j=0;j<26;j++)
{
if(letter[j]==a[i])freq[j]++;
}
}
int mx=-1;
for(int i=0;i<26;i++)
{
if(freq[i]>mx) mx=freq[i];
}
for(int i=0;i<26;i++)
{
if(freq[i]==mx)
printf("%c",letter[i]);
}
puts("");
}
return 0;
}
/* if you declare any variable outside of the main function,
c compilers keeps 0 as it's initial value;
Than if you change or scan any value for this variable c compilers change the value as your
changing.*/
//Language:C++
No comments:
Post a Comment