Code: Select all
Accepted.
![:D](./images/smilies/icon_biggrin.gif)
Moderator: Board moderators
Code: Select all
Accepted.
Code: Select all
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
char input[201];
char alphabet[26]="abcdefghijklmnopqrstuvwxyz";
char *p, *q;
int x, y, z, length, highest, localCount, cases;
int num[26];
scanf("%d",&cases);
fflush(stdin);
for(z=0; z < cases; z++){
highest = 0;
gets(input);
length = strlen(input);
p = alphabet;
q = input;
for(x = 0; x < 26; x++)
{
localCount=0;
num[x] = 0;
q = input;
for(y = 0; y < length; y++)
{
if(*p == tolower(*q))
{
num[x]++;
localCount++;
}
q++;
}
p++;
if(localCount>highest)
highest = localCount;
}
if(highest !=0){
for(x = 0; x < 26; x++)
{
if(num[x] == highest)
{
printf("%c",alphabet[x]);
}
}
}
printf("\n");
}
return 0;
}
Code: Select all
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
void INSERTION_SORT(char[],int) ;
using namespace std ;
int main ()
{
int Cnt = 0 , freq = 0,oo =-1000,Cases,index=0,LettCnt=0;
char c;
char Arr[200],Lett[100];
char Comp ;
int Count [200];
cin>>Cases;
for (int K=0;K<Cases+1;K++)
{
for (int i=0; i<200; i++)
{
scanf("%c", &c);
Arr[i] = c;
Cnt++;
if (c == '\n')
break;
}
for (int i=Cnt;i<200;i++)
{
Arr[i] = '\0';
}
for (int i=0;i<Cnt;i++)
{
if (isdigit(Arr[i])||Arr[i]==' '||Arr[i]=='\n')
{
Count[i]=oo;
}
else
{
Count[i] = 1;
}
}
for (int i=Cnt;i<200;i++)
{
Count[i] = '\0';
}
for (int i=0;i<Cnt;i++)
{
Comp = Arr[i];
for (int j=i+1;j!=Cnt+1;j++)
{
if (Arr[j]==Comp)
{
Count[i]++;
}
}
}
for (int i=0;i<Cnt;i++)
{
if (Count[i]>freq)
{
freq = Count[i];
}
}
for (int i=0;i<Cnt;i++)
{
if (Count[i]==freq)
{
Lett[LettCnt++]=Arr[i];
index++;
}
}
if(K!=0)
{
INSERTION_SORT(Lett,index);
// if(K!=Cases)
// {
cout<<endl;
// }
}
//========================= Re Initialize Arrays & Data =================
for (int i=0;i<Cnt;i++)
{
Arr[i] = '\0';
Count[i]= '\0';
}
for (int i=0;i<index;i++)
{
Lett[i] = '\0';
}
freq = 0;
Cnt = 0;
oo = -1000;
LettCnt=0;
index=0;
}
return 0 ;
}
void INSERTION_SORT(char Array[],int ArrayLength)
{
for(int j=1;j<ArrayLength;j++)
{
int key=Array[j];
int i=j-1;
while(i>=0&&Array[i]>key)
{
Array[i+1]=Array[i--];
}
Array[++i]=key;
}
for (int i=0;i<ArrayLength;i++)
{
cout<<Array[i];
}
}
Code: Select all
AC
Code: Select all
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
freopen("uvainput.txt", "r", stdin);
//freopen("uvaoutput.txt", "w", stdout);
char s[10000],rs[30],tch;
int t,tt,i,j,l,max,min,c;
const int r=123;
scanf("%d",&tt);
char gr=getchar();
for(t=1; t<=tt; t++)
{
max=0,c=0;
int a[r]={0};
gets(s);
l=strlen(s);
for(i=0;i<l;i++)
{
if(isalpha(s[i]))
{
if(isupper(s[i]))
{
j=s[i]+32;
}
else
j=s[i];
a[j]++;
}
}
//65 to 122
for(i=65;i<r;i++)
{
if(a[i]>max)
max=a[i];
}
for(i=65;i<r;i++)
{
if(a[i]==max)
{
rs[c]=i;
c++;
}
}
for(i=0; i<c-1; i++)
{
min=rs[i];
for(j=i+1; j<c; j++)
{
if(rs[j]<min)
{
min= rs[j];
tch=rs[i];
rs[i]=rs[j];
rs[j]=tch;
}
}
}
for(i=0; i<c; i++)
{
printf("%c",rs[i]);
}
}
return 0;
}
Code: Select all
#include <stdio.h>
#include <ctype.h>
int main(){
int n;
scanf("%d",&n);
getchar();
while(n--){
char s[1000],cnt[26]={0};
gets(s);
int i;
for(i=0;s[i];i++){
if(s[i]>='A' && s[i]<='Z'){
cnt[s[i]-'A']++;
}
else if(s[i]>='a' && s[i]<='z'){
cnt[s[i]-'a']++;
}
}
int max=cnt[0];
for(i=0;i<26;i++){
if(cnt[i]>max){
max=cnt[i];
}
}
for(i=0;i<26;i++){
if(cnt[i]==max){
printf("%c",i+'a');
}
}
printf("\n");
}
return 0;
}
Code: Select all
#include <stdio.h>
#include <ctype.h>
int main(){
int n;
scanf("%d",&n);
getchar();
while(n--){
char s[1000],cnt[26]={0};
gets(s);
int i;
for(i=0;s[i];i++){
if(s[i]>='A' && s[i]<='Z'){
cnt[s[i]-'A']++;
}
else if(s[i]>='a' && s[i]<='z'){
cnt[s[i]-'a']++;
}
}
int max=cnt[0];
for(i=0;i<26;i++){
if(cnt[i]>max){
max=cnt[i];
}
}
for(i=0;i<26;i++){
if(cnt[i]==max){
printf("%c",i+'a');
}
}
printf("\n");
}
return 0;
}