HDU 1075 What Are You Talking About

该题是一道字典树的题目,就是是要你翻译一下,如果你学了字典树就会发现这是一道水体;

#include<stdio.h>
#include
<stdlib.h>
#include
<string.h>
typedef
struct t
{
char num[12];
t
*ch[26];
int flag;
}tire;
tire
*empty()
{
tire
*t=( tire * )malloc( sizeof( tire ) );
for( int i=0;i<26;i++ )
t
->ch[i]=NULL;
memset( t
->num,0,sizeof( t->num ) );
t
->flag=0;
return t;
}
void build( tire *t,char c[],char num[] )
{
int i=0;
while( num[i] )
{
int x=num[i]-'a';
if( t->ch[x]==NULL )
t
->ch[x]=empty();
t
=t->ch[x];
i
++;
}
t
->flag=1;
strcpy( t
->num,c );
}
bool find( tire *t, char num[] )
{
int i=0,x;
while( num[i] )
{
x
=num[i]-'a';
if( t->ch[x]==NULL )
return false;
if( num[i+1]=='\0' )
{
if( t->ch[x]->flag )
{
printf(
"%s",t->ch[x]->num );
return true;
}
else return false;
}
i
++;
t
=t->ch[x];
}
return false;
}
int main( )
{
char c[12],num[12],x;
tire
*root=empty();
scanf(
"%s%*c",num );
while( scanf( "%s",c ),strcmp( "END",c ) )
{
scanf(
"%s",num );
build( root,c,num );
}
scanf(
"%s%*c",num );
int re=0;
while( x=getchar() )
{

if( (x<='z'&&x>='a')||(x<='Z'&&x>='A') )
{
num[re
++]=x;
}
else
{
num[re]
='\0';
if( !strcmp( "END",num ) )
break;
if( !find( root,num ) )
printf(
"%s",num );
printf(
"%c",x );
re
=0;
}
}
return 0;
}

转载于:https://www.cnblogs.com/bo-tao/archive/2011/09/04/2165951.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值