较简单字典树,每输入一对字符串,前一个放在字典(数组)中,后一个插入字典树中,并将其最终的flag赋为前一个在数组中的下标,再就好找了。输入的处理方法要注意一下。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <sstream>
using namespace std;
#define N 100027 struct node
{
int flag;
node *next[];
}*root; char dic[N][]; node *create()
{
node *p;
p = (node *)malloc(sizeof(node));
for(int i=;i<;i++)
p->next[i] = NULL;
return p;
} void insert(char *ss,int x)
{
int i = ,k;
node *p = root;
while(ss[i])
{
k = ss[i++] - 'a';
if(p->next[k] == NULL)
p->next[k] = create();
p = p->next[k];
}
p->flag = x;
} void release(node *p)
{
for(int i=;i<;i++)
{
if(p->next[i] != NULL)
release(p->next[i]);
}
free(p);
} int search(char *ss)
{
node *p = root;
int i = ,k;
while(ss[i])
{
k = ss[i++] - 'a';
if(p->next[k] == NULL)
return -;
p = p->next[k];
}
return p->flag;
} int main()
{
int k,i;
char ss[],sa[];
k = ;
root = create();
while(gets(ss) && strlen(ss))
{
sscanf(ss,"%s %s",dic[k],sa);
insert(sa,k++);
}
while(scanf("%s",sa)!=EOF)
{
i = search(sa);
if(i != -)
printf("%s\n",dic[i]);
else
puts("eh");
}
release(root);
return ;
}

ZOJ 1109 Language of FatMouse的更多相关文章

  1. zoj 1109 Language of FatMouse(map映照容器的典型应用)

    题目连接: acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1109 题目描述: We all know that FatMouse doe ...

  2. zoj 1109 Language of FatMouse(字典树)

    Language of FatMouse Time Limit: 10 Seconds      Memory Limit: 32768 KB We all know that FatMouse do ...

  3. zoj 1109 Language of FatMouse(map)

    Language of FatMouse Time Limit: 10 Seconds      Memory Limit: 32768 KB We all know that FatMouse do ...

  4. zoj 1109 zoj 1109 Language of FatMouse(字典树)

    好开心,手动自己按照字典树的思想用c写了一个优化后的trie字典树,就是用链表来代替26个大小的字符数组.完全按照自己按照自己的想法打的,没有参考如何被人的代码.调试了一天,居然最后错在一个小问题上, ...

  5. ZOJ 1109 Language of FatMouse 【Trie树】

    <题目链接> 题目大意: 刚开始每行输入两个单词,第二个单词存入单词库,并且每行第二个单词映射着对应的第一个单词.然后每行输入一个单词,如果单词库中有相同的单词,则输出它对应的那个单词,否 ...

  6. zoj 1109 Language of FatMouse 解题报告

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=109 题目意思:给出一个mouse-english词典,问对于输入的m ...

  7. ZOJ Problem Set - 1109 Language of FatMouse

    这道题目最让人头疼的就是该题的input怎么结束,因为它要求输入一个空行的时候则一串字符串输入结束,这就不得不让人绕个弯来解决这个问题. (注:本人习惯于使用C中的字符串操作,但是用到map要求使用s ...

  8. zoj1109 水题(大神绕道) Language of FatMouse

    Language of FatMouse Time Limit: 10 Seconds      Memory Limit:32768 KB We all know that FatMouse doe ...

  9. ZOJ 1108 & HDU 1160 - FatMouse's Speed

    题目大意:给你n只老鼠的体重w和速度s,让你找出最长的子序列使得w[i] < w[j] 且 s[i] > s[j] (i < j).求最长序列的长度并输出该序列. LIS(Longe ...

随机推荐

  1. Linux命令详解之—pwd命令

    Linux的pwd命令也是一个非常常用的命令,本文为大家介绍下Linux中pwd命令的用法. 更多Linux命令详情请看:Linux命令速查手册 Linux pwd命令用于显示工作目录. 执行pwd指 ...

  2. 使用openssl创建自签名证书及部署到IIS教程

    概要 本文讲解三个部分:1. 创建自签名证书2. 创建自己的证书颁发机构3. 以及如何配置IIS 创建自签名证书 首先,创建一个私钥文件: openssl genrsa -out myselfsign ...

  3. ALV用例大全

    一.ALV介绍  The ALV Grid Control (ALV = SAP List Viewer)是一个显示列表的灵活的工具,它提供了基本功能的列表操作,也可以通过自定义来进行增强,因此可以允 ...

  4. Atitit.图片木马的原理与防范 attilax 总结

    Atitit.图片木马的原理与防范 attilax 总结 1.1. 像图片的木马桌面程序1 1.2. Web 服务端图片木马1 1.3. 利用了Windows的漏洞1 1.4. 这些漏洞不止Windo ...

  5. android webview 介绍

    在Android手机中内置了一款高性能webkit内核浏览器,在SDK中封装成名为WebView的组件. WebView使用: (1)添加权限:AndroidManifest.xml中必须使用许可&q ...

  6. IOS项目集成ShareSDK实现第三方登录、分享、关注等功能。

    (1)官方下载ShareSDK iOS 2.8.8,地址:http://sharesdk.cn/ (2)根据实际情况,引入相关的库,参考官方文档. (3)在项目的AppDelegate中一般情况下有三 ...

  7. 【文章内容来自《Android 应用程序开发权威指南》(第四版)】如何设计兼容的用户界面的一些建议(有删改)

    最近一直在看的一本书是<Android 应用程序开发权威指南>(第四版),十分推荐.书中讲到了一些用户界面设计的规范,对于初学者我认为十分有必要,在这里码给大家,希望对我们都有用. 在我们 ...

  8. C++语言-02-函数

    普通函数 C++是在C语言的基础上增加了面向对象特性的语言,是C语言的超集 C++中的普通函数与C语言中的普通函数具有类似的性质.请参照以下博客:C语言-04-函数 与类相关的函数 C是一种OOP语言 ...

  9. 提示“正尝试安装的adobe flash player不是最新版本”的解决方法

    尼玛,今天下午遇到一个比较奇怪的现象,我电脑的flash的不能正常使用了,我下载了一个重新安装了下,但还是不行.然后我又卸载了,重新安装flash,重启电脑,还是不行...而且在安装flash pla ...

  10. maven 错误No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format

    [INFO] Scanning for projects... [INFO] ------------------------------------------------------------- ...