import java.io.*;
class rank{
String[] data=new String[50000];
String[] dic=new String[50000];
String[][] word=new String[500][10000];
int[][] nword=new int[500][10000];
int[] num=new int[30000];
int[] rank=new int[1000];
String[] xml=new String[20000];
String str,file;
int[] wordnumber=new int[500];
int s,sx,datanumber,xmlnumber;
int dicnumber,page,dx,dxs;
public static void main(String[] args){
rank test=new rank();
}
rank(){
dicnumber=0;
readfile("dic.txt");
dicnumber=datanumber;
for(s=1;s<dicnumber+1;s++){
dic[s]=data[s];
}
for(page=1;page<220;page++){
file="nword/";
file=file+page;
file=file+".txt";
readfile(file);
for(s=1;s<datanumber+1;s++){
str=data[s];
xymaker(str);
for(sx=1;sx<xmlnumber+1;sx++){
nword[s][sx]=Integer.parseInt(xml[sx]);
}
wordnumber[s]=xmlnumber;
}
for(s=1;s<datanumber+1;s++){
for(sx=1;sx<wordnumber[s]+1;sx++){
dx=nword[s][sx];
num[dx]=num[dx]+1;
}
}
}
makerank();
writefile();
}
void writefile(){
int s,sx;
try{
PrintWriter pw = new PrintWriter
(new BufferedWriter(new FileWriter("rank.txt")));
for(s=1;s<1000;s++){
sx=rank[s];
pw.println(dic[sx]);
}
System.out.println("ファイルに書きこみました。");
pw.close();
}
catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
void makerank(){
int r,s,sx,maxn,h;
int[] ch=new int[30000];
for(r=1;r<1000;r++){
maxn=0;
sx=0;
for(s=1;s<dicnumber+1;s++){
h=0;
if(num[s]>maxn)h=h+1;
if(ch[s]<50)h=h+1;
if(h==2)maxn=num[s];
if(h==2)sx=s;
}
rank[r]=sx;
ch[sx]=100;
}
}
void xymaker(String str){
int sx,p1;
int[] x=new int[10000];
int[] y=new int[10000];
sx=1;
p1=str.indexOf("<");
x[1]=p1;
while(p1>-1){
p1=str.indexOf("<",p1+1);
if(p1>0)sx=sx+1;
if(p1>0)x[sx]=p1;
}
xmlnumber=sx;
for(sx=1;sx<xmlnumber+1;sx++){
y[sx]=str.indexOf(">",x[sx]);
}
for(sx=1;sx<xmlnumber+1;sx++){
xml[sx]=str.substring(x[sx]+1,y[sx]);
}
}
void readfile(String file){
String str;
BufferedReader br;
s=0;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(file),"SJIS"));
while((str = br.readLine()) != null) {
s=s+1;
data[s]=str;
}
br.close();
} catch (IOException e) {System.out.println(e);}
datanumber=s;
}
}
最終更新:2011年07月04日 16:02