Algorithm 版 (精华区)
发信人: Lerry (想不开·撞树), 信区: Algorithm
标 题: triples.c
发信站: 哈工大紫丁香 (2002年06月09日21:31:39 星期天), 站内信件
/*
* NoseyParker, the search engine for FTP archives
* Copyright (C) 1993-96 by Jiri A. Randus
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* The author can be reached as follows:
* Internet: <Jiri.Randus@vslib.cz>
* Phone: ++42 48 5227374
* SnailMail: Jiri Randus
* KIN HF TU v Liberci
* Halkova 6
* 46117 Liberec
* Czech Republic
*/
#define TRIPLES_VERSION "1.1"
#include "parker.h"
#include <malloc.h>
union TripleField { union TripleField *lower[TOP256];
char ok[TOP256];
};
union TripleField TFtoplevel;
void Process(char *key)
{
int i,c;
union TripleField *TFptr;
TFptr=&TFtoplevel;
for(i=0;i<(KEYSIZE-1);i++)
{
c=tolower(*((unsigned char *)(key+i)));
if(!TFptr->lower[c]) {
TFptr->lower[c]=malloc(sizeof(union TripleField));
memset(TFptr->lower[c], 0, sizeof(union TripleField));
}
TFptr=TFptr->lower[c];
}
c=tolower(*((unsigned char*)(key+KEYSIZE-1)));
TFptr->ok[c]=1;
}
void DumpTriples(char *prefix, union TripleField *ptr, int depth)
{
int i;
char newkey[KEYSIZE+1];
if(depth==(KEYSIZE-1)) {
for(i=0;i<TOP256;i++) if(ptr->ok[i]) printf("%s%c\n",prefix,i);
}
else {
for(i=0;i<TOP256;i++) if(ptr->lower[i]!=NULL) {
sprintf(newkey,"%s%c",prefix,i);
DumpTriples(newkey, ptr->lower[i],depth+1);
}
}
}
void main(void)
{
char buffer[MAX], *ptr;
int len;
int i;
if(!feof(stdin)) while(1) {
fgets(buffer,MAX,stdin);
if(feof(stdin)) break;
ptr=buffer;
while(*ptr!=' '&& *ptr!=0 ) ptr++;
*ptr='\0';
if((ptr=strchr(buffer,CR))!=NULL) *ptr='\0';
if((ptr=strchr(buffer,LF))!=NULL) *ptr='\0';
if((ptr=strchr(buffer,ESC))!=NULL) *ptr='\0';
len=strlen(buffer)-KEYSIZE;
for(i=0;i<=len;i++) Process(&buffer[i]);
}
DumpTriples("",&TFtoplevel,0);
}
--
当一个女孩儿觉得她不太容易了解那个男人的时候,她会爱他。
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 天外飞仙]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.322毫秒