PAT1032. Sharing

To store English words, one method is to use linked lists and store a word letter by letter.  To save some space, we may let the words share the same sublist if they share the same suffix.  For example, "loading" and "being" are stored as showed in Figure 1.

Figure 1

You are supposed to find the starting position of the common suffix (e.g. the position of "i" in Figure 1).

Input Specification:

Each input file contains one test case.  For each case, the first line contains two addresses of nodes and a positive N (<= 105), where the two addresses are the addresses of the first nodes of the two words, and N is the total number of nodes.  The address of a node is a 5-digit positive integer, and NULL is represented by -1.

Then N lines follow, each describes a node in the format:

Address Data Next

where Address is the position of the node, Data is the letter contained by this node which is an English letter chosen from {a-z, A-Z}, and Next is the position of the next node.

Output Specification:

For each case, simply output the 5-digit starting position of the common suffix.  If the two words have no common suffix, output "-1" instead.

Sample Input 1:

11111 22222 9
67890 i 00002
00010 a 12345
00003 g -1
12345 D 67890
00002 n 00003
22222 B 23456
11111 L 00001
23456 e 67890
00001 o 00010

Sample Output 1:

67890

Sample Input 2:

00001 00002 4
00001 a 10001
10001 s -1
00002 a 10002
10002 t -1

Sample Output 2:

-1思路:本体其实用哈希思想解决更好,但是本人利用了常规解法,将长度拼成相等,然后进行同时扫描。本题有一处需要注意的是:scanf("%c"); %c是可以加入空格的。
时间: 2025-01-07 11:13:45

PAT1032. Sharing的相关文章

pat1032. Sharing (25)

1032. Sharing (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To store English words, one method is to use linked lists and store a word letter by letter. To save some space, we may let the words share the same sublist if the

跟Google 学代码 :Building Apps with Content Sharing(跟女神去表白)

本篇博客都讲了些什么? 1. Sharing Simple Data 共享简单的数据,如文本,图片,URI 2. Sharing Files 共享文件 3. Sharing Files with NFC无线传输 在写博客之前,假设 "我"是服务端App,我的"女神"是客户端App 情书是"我"想传递的数据 那么我该如何做呢? 向客户端App发送数据(暗送秋波篇) 对女神爱在心中口难开怎么办?如何示爱这是穷学生最纠结的心病 在Android 开发中

HDU-1034-Candy Sharing Game(C++ &amp;&amp; 简单模拟)

Candy Sharing Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3703    Accepted Submission(s): 2311 Problem Description A number of students sit in a circle facing their teacher in the cent

win7主机与linux虚拟机共享方法之右键添加Sharing Options

在win7上建了个linux虚拟机,虚拟机中装好samba. 如果对着文件夹进行右键操作,没发现Sharing Options,再执行下面的安装: sudo apt-get install nautilus-share 重启虚拟机后即可生效.

OpenMp之false sharing

关于false sharing的文章,网上一大堆了,不过觉得都不太系统,那么下面着重系统说明一下. 先看看外国佬下的定义: In symmetric multiprocessor (SMP) systems, each processor has a local cache. The memory system must guarantee cache coherence. False sharing occurs when threads on different processors mod

Devstack: A copy of worked local.conf I&#39;m sharing with you.

service_plugins = neutron.services.firewall.fwaas_plugin.FirewallPlugin [service_providers] service_provider=LOADBALANCER:Haproxy:neutron.services.loadbalancer.drivers.haproxy.plugin_driver.Haproxy OnHostPluginDriver:default [fwaas] driver = neutron.

跨域的另一种解决方案CORS(CrossOrigin Resource Sharing)跨域资源共享

在我们日常的项目开发时使用AJAX,传统的Ajax请求只能获取在同一个域名下面的资源,但是HTML5打破了这个限制,允许Ajax发起跨域的请求.浏览器是可以发起跨域请求的,比如你可以外链一个外域的图片或者脚本.但是Javascript脚本是不能获取这些资源的内容的,它只能被浏览器执行或渲染.主要原因还是出于安全考虑,浏览器会限制脚本中发起的跨站请求.(同源策略, 即JavaScript或Cookie只能访问同域下的内容).跨域的解决方案有多重JSONP.Flash.Iframe等,当然还有COR

CUPS/Printer sharing

https://wiki.archlinux.org/index.php/CUPS/Printer_sharing_(简体中文) GNU/Linux系统间共享 在作为打印服务器的GNU/Linux系统(服务器端)上安装好CUPS之后,建议您通过网页操作界面与另一个GNU/Linux系统(客户端)共享打印机:当然您也可以选择手动操作共享. 在启动cupsd之前,您需要保证avahi-daemon处于运行状态. 您的客户端需要支持Avahi主机名解析,否则客户端可能报错称"找不到打印机"(

解决 internet connection sharing 启动不了

1.恢复默认服务 @echo 恢复windows7系统默认服务 @pause sc config AeLookupSvc start= DEMAND sc config ALG start= DEMAND sc config AppIDSvc start= DEMAND sc config Appinfo start= DEMAND sc config AppMgmt start= DEMAND sc config AudioEndpointBuilder start= AUTO sc conf