class pro{
String str;
String[] ph=new String[100];
double[] p=new double[100];
int phnumber,dicnumber,wordnumber;
int[] num=new int[100];
String[] word=new String[100];
int[] nword=new int[100];
String[] dic=new String[100];
int[] np=new int[100];
int s,sx;
int t1;
public static void main(String args[]){
pro test=new pro();
}
pro(){
p[0]=1;
dicnumber=0;
str="朝は朝です";
t1=0;
while(t1<100){
makeword(str);
for(s=1;s<wordnumber+1;s++){
if(nword[s]<1)makedic(s);
}
for(s=0;s<dicnumber+1;s++){
num[s]=1;
}
for(s=1;s<wordnumber+1;s++){
if(nword[s]>0)sx=nword[s];
if(nword[s]>0)num[sx]=num[sx]+1;
if(nword[s]<1)makep(s);
}
for(s=0;s<dicnumber+1;s++){
p[s]=(double)num[s]/wordnumber;
}
t1=t1+1;
}
}
void makep(int s){
int sx,sxs;
sxs=0;
for(sx=1;sx<dicnumber+1;sx++){
if(word[s].equals(dic[sx]))sxs=sx;
}
num[sxs]=num[sxs]+1;
}
void makedic(int s){
int sx,h;
h=0;
for(sx=1;sx<dicnumber+1;sx++){
if(word[s].equals(dic[sx]))h=100;
}
if(h<50)dicnumber=dicnumber+1;
if(h<50)dic[dicnumber]=word[s];
}
void makeword(String str){
int s,n;
double p1,maxp;
for(s=1;s<100;s++){
word[s]="";
}
for(s=1;s<100;s++){
nword[s]=0;
}
maxp=-999;
for(n=1;n<11;n++){
makeph(str);
makenp();
p1=point();
if(p1>maxp)word=ph;
if(p1>maxp)nword=np;
if(p1>maxp)wordnumber=phnumber;
if(p1>maxp)maxp=p1;
}
}
double point(){
double pt;
int s,sx;
sx=np[1];
pt=p[sx];
for(s=2;s<phnumber+1;s++){
sx=np[s];
pt=pt*p[sx];
}
return pt;
}
void makenp(){
int s,sx;
for(s=1;s<phnumber+1;s++){
np[s]=0;
for(sx=1;sx<dicnumber+1;sx++){
if(ph[s].equals(dic[sx]))np[s]=sx;
}
}
}
void makeph(String str){
int[] z=new int[100];
int[] zz=new int[100];
int s,sx,zlong;
zlong=str.length();
z[0]=1;
for(s=1;s<zlong;s++){
z[s]=0;
if(Math.random()>0.5)z[s]=1;
}
sx=1;
zz[1]=0;
for(s=1;s<zlong;s++){
if(z[s]==1)sx=sx+1;
if(z[s]==1)zz[sx]=s;
}
phnumber=sx;
for(s=1;s<phnumber;s++){
ph[s]=str.substring(zz[s],zz[s+1]);
}
s=phnumber;
ph[s]=str.substring(zz[s],zlong);
}
}
最終更新:2011年05月23日 06:05