アットウィキロゴ

jhgfdさ

class pro{

String str,ph;
String[] dic=new String[100];
int[] gototx=new int[100];
int[] num=new int[100];
double[] p=new double[100];  
double[] pr=new double[101];  
double[] q=new double[100];  
double[] v=new double[100];  
int dicnumber,wordnumber,phnumber;
int strlong,s,sx,sxs;
String[] word=new String[100];
String[] phx=new String[100];
double p1,maxv,v1;
int t,tx,txs;
int h;
int tr;

public static void main(String args[]){
pro test=new pro();
}

pro(){

makepr();

p[0]=1;
dicnumber=0;

str="総務省が27日発表した4月の全国消費者物価";

strlong=str.length();

ph=str.substring(0,1);

p1=p[0];
for(sx=1;sx<dicnumber+1;sx++){
if(ph.equals(dic[sx]))p1=p[sx];
}
v[0]=p1;
for(t=1;t<strlong;t++){
ph=str.substring(0,t+1);
p1=p[0];
for(sx=1;sx<dicnumber+1;sx++){
if(ph.equals(dic[sx]))p1=p[sx];
}
phnumber=ph.length();
maxv=pr[phnumber]*p1;
txs=-1;
for(tx=0;tx<t;tx++){
ph=str.substring(tx+1,t+1);
p1=p[0];
for(sx=1;sx<dicnumber+1;sx++){
if(ph.equals(dic[sx]))p1=p[sx];
}
phnumber=ph.length();
p1=pr[phnumber]*p1;
v1=p1*v[tx];
if(v1>maxv)txs=tx;
if(v1>maxv)maxv=v1;
}
gototx[t]=txs;
v[t]=maxv;
}

sx=0;
t=strlong-1;
while(tx>0){
tx=gototx[t];
sx=sx+1;
phx[sx]=str.substring(tx+1,t+1);
t=tx;
}
sx=sx+1;
phx[sx]=str.substring(0,t+1);
wordnumber=sx;
for(sx=1;sx<wordnumber+1;sx++){
word[sx]=phx[wordnumber+1-sx];
}

System.out.println(wordnumber);


for(s=1;s<wordnumber+1;s++){
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];
}

for(sx=1;sx<dicnumber+1;sx++){
num[sx]=0;
}  

for(s=1;s<wordnumber+1;s++){
sxs=0;
for(sx=1;sx<dicnumber+1;sx++){
if(word[s].equals(dic[sx]))h=100;
}  
num[sxs]=num[sxs]+1;
}

for(sx=1;sx<dicnumber+1;sx++){
q[sx]=(double)num[sx]/wordnumber;
}  

for(sx=1;sx<dicnumber+1;sx++){
p[sx]=0.9*p[sx]+0.1*q[sx];
}  

}

void makepr(){
double p1,c1,c2;
int k;
p1=0.5;
c1=0;
for(k=1;k<101;k++){
c1=c1+Math.pow(1-p1,k)*p1;
}  
for(k=1;k<101;k++){
pr[k]=Math.pow(1-p1,k)*p1/c1;
}

}
最終更新:2011年05月27日 14:17