C/C++の宿題を片付けます 100at TECH
C/C++の宿題を片付けます 100 - 暇つぶし2ch316:デフォルトの名無しさん
07/11/27 18:06:06
>>310
#include <stdio.h>
#include <string.h>
#include <math.h>
int main()
{
int i=0,l,c[256]={0};
char buf[256];
double h=0,p;
scanf("%s",buf);
l=strlen(buf);
for(i=0;i<l;i++)
c[buf[i]]++;
for(i=0;i<256;i++)
if(c[i]>0) {
p=(double)c[i]/l;
printf("\"%c\" %lf\n",i,p);
h-=p*log(p);
}
printf("H = %lf\n",h);
return 0;
}


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch