What's The Frequency, Kenneth?
Type: Sorting & Searching
Diff: 3.0
Input |
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define MAX 100
int his[260][3];
void bbls(int n)
{int hold,j,pass;
int sw=1;
for(pass=0;pass < n-1 && sw ==1 ; pass++ )
{sw = 0;
for(j=0;j < n-pass-1; j++)
if(his[j][1] < his[j+1][1])
{sw = 1;
hold = his[j][1];
his[j][1] = his[j+1][1];
his[j+1][1] = hold;
hold = his[j][0];
his[j][0] = his[j+1][0];
his[j+1][0] = hold;
}}}/*char *strupper(char *str)
{char rst[MAX];
register int i=0;
while(*str)
{rst[i++]=toupper(*str);
str++;
}rst[i++] = '\0';
return rst;
}*/main()
{char str[MAX],ch;
long int n,len;
// freopen("c:\\tc\\temp\\input.in","rt",stdin);
// scanf("%ld\n",&n);
// scanf("%c",ch);
while(gets(str))
{// strcpy(str,strupper(str));
for(n=0;n<260;n++)
{his[n][0]=n;
his[n][1]=0;
}len=(strlen(str)) ? (strlen(str)-1) : 0;
while(len>=0)
{if( ((str[len]>='A') && (str[len]<='Z')) ||
((str[len]>='a') && (str[len]<='z')) )
his[str[len]][1]++;
len--;
}bbls(260);
n=0;
//spacebar elliminate
while(his[0][1]==his[n][1])
{if(his[n][1])
putchar(his[n][0]);
n++;
}printf(" %d\n",his[0][1]);
}return 0;} |
|