Posted on 2012-08-18 11:43
hoshelly 閱讀(210)
評論(0) 編輯 收藏 引用 所屬分類:
Programming
編寫一程序,接受一個字符串作為參數,并打印一張表。對于在字符串中出現的每個字符,該表給出該字符以及它的出現頻率。
代碼測試通過:
#include<stdio.h>
#define N 1000
int main()
{
char a[N];
int b[N]={0};
int i,c[N]={0};
printf("Input the string: ");
gets(a);
for(i=0;a[i]!='\0';i++)
{
b[a[i]]++;
}
for(i=0;a[i]!=0;i++)
{
if(c[a[i]] == 0)
{
printf("%c : %d\n",a[i],b[a[i]]);
c[a[i]]=1;
}
}
printf("\n");
return 0;
}