A1032. 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 Nextis 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
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef struct nd{
int rt;
char alfa;
int isFirst;
nd(){
isFirst = ;
}
}node;
node data[];
int main(){
int w1, w2, N;
scanf("%d%d%d", &w1, &w2, &N);
int temp1, temp2;
char c;
for(int i = ; i < N; i++){
scanf("%d %c %d", &temp1, &c, &temp2);
data[temp1].alfa = c;
data[temp1].rt = temp2;
}
int pt = w1;
while(pt != -){
data[pt].isFirst = ;
pt = data[pt].rt;
}
int find = -;
pt = w2;
while(pt != -){
int tag = , pt2 = pt;
if(data[pt].isFirst == ){
while(pt2 != -){
if(data[pt2].isFirst != ){
tag = ;
break;
}
pt2 = data[pt2].rt;
}
if(tag == ){
find = pt;
break;
}
}
pt = data[pt].rt;
}
if(find == -)
printf("-1");
else printf("%05d", find);
cin >> N;
return ;
}
总结:
1、在地址很小的时候,为了方便一般使用静态数组。
A1032. Sharing的更多相关文章
- PAT甲级——A1032 Sharing
To store English words, one method is to use linked lists and store a word letter by letter. To save ...
- PAT-链表-A1032 Sharing
题意:给出两条链表的首地址以及若干个节点的的地址.数据.下一个节点的地址,求两条链表的首个共用节点的地址.如果两条链表没有共用节点,则输出-1. 思路:使用静态链表,首先遍历一遍第一个链表并进行标记. ...
- PAT A1032 Sharing
题意:给出两条链表的首地址以及若干节点的地址,数据,下一个节点的地址,求两条链表的首个共用节点的地址.如果两条链表没有共用节点,则输出-1.思路步骤1:由于地址的范围很小,因此可以直接用静态链表,但是 ...
- PAT甲级题解分类byZlc
专题一 字符串处理 A1001 Format(20) #include<cstdio> int main () { ]; int a,b,sum; scanf ("%d %d& ...
- 伪共享(false sharing),并发编程无声的性能杀手
在并发编程过程中,我们大部分的焦点都放在如何控制共享变量的访问控制上(代码层面),但是很少人会关注系统硬件及 JVM 底层相关的影响因素.前段时间学习了一个牛X的高性能异步处理框架 Disruptor ...
- Salesforce的sharing Rule 不支持Lookup型字段解决方案
Salesforce 中 sharing rule 并不支持Look up 字段 和 formula 字段.但在实际项目中,有时会需要在sharing rule中直接取Look up型字段的值,解决方 ...
- [Erlang 0127] Term sharing in Erlang/OTP 上篇
之前,在 [Erlang 0126] 我们读过的Erlang论文 提到过下面这篇论文: On Preserving Term Sharing in the Erlang Virtual Machine ...
- 跨域的另一种解决方案——CORS(Cross-Origin Resource Sharing)跨域资源共享
在我们日常的项目开发时使用AJAX,传统的Ajax请求只能获取在同一个域名下面的资源,但是HTML5打破了这个限制,允许Ajax发起跨域的请求.浏览器是可以发起跨域请求的,比如你可以外链一个外域的图片 ...
- 006_Salesforce Sharing 使用说明
Salesforce Sharing 使用说明 背景说明:Salesforce共享实施记录和其它数据时,需要员工之间共享或多个用户在一个组织间的共享.然而,共享这些数据是有风险的,尤其是当它涉及到敏感 ...
随机推荐
- 【DDD】使用领域驱动设计思想实现业务系统
最近新接了一个业务系统——社区服务系统,为了快速熟悉和梳理老系统的业务逻辑和代码,同时对老系统代码做一些优化,于是打算花上一个月时间不间断地对老系统服务进行重构.同时,考虑到社区业务的复杂性,想起了之 ...
- WordPress更新提示无法创建目录的解决方案
上一篇我们说到无法连接FTP服务器,我们已经完美的解决了,然后...发现...还是无法更新,啥情况??? 提示为无法创建目录 原因是执行更新程序的是www用户, 解决方案如下: 需要把插件或主程序下载 ...
- linux-安装-源码安装
编译安装 tengine
- SE Class's Individual Project--12061161 赵梓皓
1. 项目预计的用时 其实刚开始以为这个项目不难写,因为上学期oo课程上用java写过类似的程序(貌似还比这个复杂).觉得主要的难点在于学习c++语言. 总的项目被分为大概3个部分. 其一,文件遍历. ...
- Echo团队便利记事本项目终审报告
一.团队成员简介 http://www.cnblogs.com/echo-buaa/p/3991968.html 二.团队项目的目标,预期的典型用户,预期的功能描述,预期的用户数量在哪里? 项目的目标 ...
- 20135316Linux内核学习笔记第八周
20135316王剑桥<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC 1000029000 一.进程调度与进程调度的时机分析 ...
- Beta版发布说明
我们的作品“校友聊”软件的最终版本于6月19日最终发布了,下面我们将对自己的产品进行介绍. 在使用之前,首先要进行用户注册,用户可以自行设置自己的账号,姓名,密码,签名,头像等信息,头像信息也可以在文 ...
- 软件工程项目之摄影App
摄影app 开发人员:Ives & Dyh 开发功能: 摄影师注册与认证,为年轻摄影师提供成长的空间,发挥一技之长的平台. 用户注册与验证,为有摄影需求的人提供选择摄影师进行个性化拍摄的平台. ...
- pycharm5.0 快捷键大全osx
官网链接https://resources.jetbrains.com/assets/products/pycharm/PyCharm_ReferenceCard_mac.pdf 一直想给别人安利py ...
- 《ERP系统修正数据的sql文件》
第一 1.修正销售客户创建者的sql脚本: UPDATE e_sales_customers sc SET sc.user_id = ( SELECT tmp.user_id FROM ( SELEC ...