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共享实施记录和其它数据时,需要员工之间共享或多个用户在一个组织间的共享.然而,共享这些数据是有风险的,尤其是当它涉及到敏感 ...
随机推荐
- 利用 John the Ripper 破解用户登录密码
一.什么是 John the Ripper ? 看到这个标题,想必大家都很好奇,John the Ripper 是个什么东西呢?如果直译其名字的话就是: John 的撕裂者(工具). 相比大家都会觉得 ...
- C/C++中int128的那点事
最近群友对int128这个东西讨论的热火朝天的.讲道理的话,编译器的gcc是不支持__int128这种数据类型的,比如在codeblocks 16.01/Dev C++是无法编译的,但是提交到大部分O ...
- Centos下Nodejs+npm环境-部署记录
公司的一个项目上线,需要用到Nodejs和npm环境,这里记录下安装过程,方便回看同时供大家参考. 1)yum安装方式(版本比较老点,v5.12.0 + 3.8.6) 需要在centos中添加epel ...
- poj3126 Prime Path(c语言)
Prime Path Description The ministers of the cabinet were quite upset by the message from the Chief ...
- 第一次Spring总结
第一阶段:下载了类似app使用,并做了对比,分析,对自己的app有了一些构思,完成了环境的配置.在这一阶段,一开始只有两个女生显得有点弱,面对从未接触过的app项目,首先就是配置环境方面的,在经过班上 ...
- mysql数据库忘记密码时如何修改
工具/原料 mysql数据库 cmd命令行 打开mysql.exe和mysqld.exe所在的文件夹,复制路径地址 打开cmd命令提示符,进入上一步mysql.exe所在的文件夹
- [转帖]Nginx的超时keeplive_timeout配置详解
Nginx的超时keeplive_timeout配置详解 https://blog.csdn.net/weixin_42350212/article/details/81123932 Nginx ...
- [CNBETA]Intel CPU底层漏洞事件完全详解:全球手机/电脑无一幸免[转帖]
http://www.cnbeta.com/articles/tech/685897.htm 由Intel CPU漏洞问题衍生出来的安全事件已经波及全球几乎所有的手机.电脑.云计算产品,ARM确认 C ...
- Bootstrap @Media分类
手机的屏幕比较小,宽度通常在600像素以下:PC的屏幕宽度,一般都在1000像素以上(目前主流宽度是1366×768)设置相应的min-width和max-width值 所以响应式设计一般对600 ...
- 自定义控件DataPager
在最近的一个项目中,涉及到一个自定义翻页控制的控件,下面就这一个控件做详细的说明,这个自定义控件的主要作用是对数据源进行翻页控制,比如说:“上一页.下一页.首页.末页”等相关操作,由于在一个项目中有多 ...