博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HNUSTOJ-1253 Babelfish(字典树)
阅读量:6756 次
发布时间:2019-06-26

本文共 2203 字,大约阅读时间需要 7 分钟。

 

1253: Problem C: Babelfish

时间限制: 1 Sec  内存限制: 128 MB
提交: 14  解决: 3
[][][]

题目描述

 

Problem C: Babelfish

You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign language. Fortunately, you have a dictionary to help you understand them.

Input consists of up to 100,000 dictionary entries, followed by a blank line, followed by a message of up to 100,000 words. Each dictionary entry is a line containing an English word, followed by a space and a foreign language word. No foreign word appears more than once in the dictionary. The message is a sequence of words in the foreign language, one word on each line. Each word in the input is a sequence of at most 10 lowercase letters. Output is the message translated to English, one word per line. Foreign words not in the dictionary should be translated as "eh".

输入

 

输出

 

样例输入

dog ogdaycat atcaypig igpayfroot ootfrayloops oopslayatcayittenkayoopslay

样例输出

catehloops
#include
#include
#include
using namespace std;const int N = 110000 + 5; struct node{ int v; struct node *next[26];}*T; node *newnode(){ node *p = new node; for(int i = 0; i < 26; i++) p -> next[i] = NULL; return p;} void Insert(node *p, char *str, int v){ int c, len = strlen(str); for(int i = 0; i < len; i++){ if(!islower(str[i])) continue; c = str[i] - 'a'; if(p -> next[c] == NULL) p -> next[c] = newnode(); p = p -> next[c]; } p -> v = v;} int Query(node *p, char *str){ int c, len = strlen(str); for(int i = 0; i < len; i++){ if(!islower(str[i])) continue; c = str[i] - 'a'; if(p -> next[c] == NULL) return 0; p = p -> next[c]; } return p -> v;}char dic[N][15], str[30];int main(){ int cur = 0; T = newnode(); while( ++cur ){ fgets(str, 30, stdin); if(isspace(str[0])) break; sscanf(str, "%s %s", dic[cur], str); Insert(T, str, cur); } while(fgets(str, 30, stdin) != NULL){ if(isspace(str[0])) break; cur = Query(T, str); printf("%s\n", cur? dic[cur]: "eh"); }}

 

 

转载于:https://www.cnblogs.com/Pretty9/p/7406788.html

你可能感兴趣的文章
Direct3D 11 Tutorial 7:Texture Mapping and Constant Buffers_Direct3D 11 教程7:纹理映射和常量缓冲区...
查看>>
Objective C内存管理进阶(一):实践准则
查看>>
TrackPoint_configure_ThinkPad_squeeze(06-16.2011)
查看>>
CSDN博客频道“移动开发之我见”主题征文活动
查看>>
PHPExcel常用方法汇总
查看>>
用户登陆的业务流程架构设计
查看>>
创建表的备份和删除
查看>>
HTML data属性
查看>>
Java 第一个程序 HelloWorld!
查看>>
weblogic.cluster.MulticastMonitor, monitoring multicast traffic in a Weblogic Cluster
查看>>
android 通过修改图片像素实现CircleImageView
查看>>
私服 Nexus 的配置
查看>>
Linux System and Performance Monitoring(Network篇)
查看>>
XenServer关闭电源以后部分虚机无法启动
查看>>
IIS部署flask之实现文件上传功能
查看>>
redis开机启动
查看>>
XaaS ------什么都是一种服务
查看>>
Linux下磁盘配额
查看>>
从雅迪赞助FIFA世界杯透视体育营销趋势
查看>>
Android通过APN进行网络连接
查看>>