<分区>
我有一个二维数组,其中顶行是一行字母(字母表),底行是它上面的字母在字符串中出现的频率。这个想法是将字母按频率顺序排列在顶行。
目前:
输入:
quickbrownfoxjumpsoverthelazydog
输出:
abcdefghijklmnopqrstuvwxyz
11112111111111411211211111
期望的输出:
oeruabcdfghijklmnpqstvwxyz
42221111111111111111111111
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
main()
{
char string[100];
char s[26][2];
int c = 0, count[26] = {0};
printf("Enter a string\n");
gets(string);
while ( string[c] != '\0' )
{
if ( string[c] >= 'a' && string[c] <= 'z' )
count[string[c]-'a']++;
c++;
}
for ( c = 0 ; c < 26 ; c++ )
{
if( count[c] != 0 )
{
s[c][1]=c+'a';
s[c][2]= (char)(((int)'0')+count[c]);
gotoxy(c,1);
printf("%c",s[c][1]);
gotoxy(c,2);
printf("%c",s[c][2]);
}
}
return 0;
}