PAT甲级(Advanced Level)真题–1046 Sharing

通过:648
提交:1138
通过率:56%


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

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

输入描述:
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.

输出描述:
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.
对于每种情况,只需输出公共后缀的5位起始位置。如果这两个单词没有共同的后缀,则输出“-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

输出例子:

67890

题目很简单,使用集合去重就可以了。

Python代码如下:

x=input().strip().split(' ')
temp=set()
flag=0
for i in range(0,int(x[2])):y=input().strip().split(' ')if y[2] in temp:flag=y[2]else:temp.add(y[2])
if flag==0:print("-1")
else:print(flag)

PAT甲级(Advanced Level)真题--1046 Sharing相关推荐

  1. PAT甲级(Advanced Level)真题-- 1062 To Buy or Not to Buy

    PAT甲级(Advanced Level)真题-- 1062 To Buy or Not to Buy 通过:643 提交:1220 通过率:52% Eva would like to make a ...

  2. A1124 Raffle for Weibo Followers(20分)PAT 甲级(Advanced Level) Practice(C++)满分题解【map】

    John got a full mark on PAT. He was so happy that he decided to hold a raffle(抽奖) for his followers ...

  3. PAT乙级(Basic Level)真题--跟奥巴马一起编程(15)

    这道题本身不难,但是题目给的有点不清楚,导致当时做这道题被坑了好久,最后看了别人的解答才知道掉进坑里了. 题目描述 美国总统奥巴马不仅呼吁所有人都学习编程,甚至以身作则编写代码,成为美国历史上首位编写 ...

  4. A1166 Summit(25分)PAT甲级 (Advanced Level) Practice(C++)满分题解【图】

    A summit (峰会) is a meeting of heads of state or government. Arranging the rest areas for the summit ...

  5. 2020年PAT甲级春季考试真题及答案

    1168 Prime Day The above picture is from Sina Weibo, showing May 23rd, 2019 as a very cool "Pri ...

  6. PAT乙级(Basic Level)真题 在霍格沃茨找零钱

    题目描述 如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 -- 就如海格告诉哈利的:"十七个银西可(Sickle)兑一个加隆(Galleon),二 十九个纳特(Knut)兑一个西可 ...

  7. PAT乙级(Basic Level)真题-1014 科学计数法 (20)

    科学计数法 (20) 时间限制 1000 ms 内存限制 32768 KB 代码长度限制 100 KB 判断程序 Standard (来自 小小) 题目描述 科学计数法是科学家用来表示很大或很小的数字 ...

  8. 2020年9月PAT甲级满分必备刷题技巧

    2020年7月的考试结束了,除了本次的考题更新,短期内不会更新. [7月题目的特点:首次线上考试,没出链表.树相关的模板题,第2到4题背景新颖,大大降低了抄袭历年代码的可能性,可以看作是线上考试的新趋 ...

  9. 【PAT甲级】A1001-A1050刷题记录

    文章目录 A1001 A+B Format (20 分) 0.25 ★(一元多项式加法) A1002 A+B for Polynomials (25 分) 0.21 (单源最短路Dijkstra+边权 ...

最新文章

  1. Nginx错误日志说明
  2. mdcsoft服务器网络安全解决方案-SQL注入解决
  3. 数据库事务转载基础一:oarcle事务
  4. GraphQL入门2
  5. mysql 运维 最佳实践_Mysql 开发最佳实践
  6. springmvc 中文文档
  7. php 文章读取_php实现获取文章内容第一张图片的方法
  8. 862. 和至少为 K 的最短子数组
  9. .jardesc文件
  10. ssh解决root_unlock_time问题
  11. idea docker 一键部署实战
  12. 于谦一共收了几个徒弟,为什么?
  13. ubuntu16.04下载opencv3.4
  14. 微信小程序-获取QQ音乐直链
  15. 很哇塞的网页特效之字符串切换
  16. 【故障分析】基于主成分分析实现三容水箱故障诊断附matlab代码
  17. 手机怎么设置腾达路由器后显示远端服务器,怎么用手机设置腾达路由器
  18. 查找算法之斐波那契查找算法
  19. 数据杂谈:CIO和CTO的区别(首席信息官首席技术官)
  20. 一只喵的西行记-4 蛋蛋的忧桑

热门文章

  1. ISME:水库蓝藻影响真核浮游生物的群落演替和物种共存
  2. ggClusterNet---一条代码完成全内容微生物网络
  3. R语言使用caret包的preProcess函数进行数据预处理:对所有的数据列进行center中心化、scale标准化(每个数据列减去平均值、除以标准差)、设置参数为center和scale
  4. python使用matplotlib可视化不同年份、不同项目的均值(mean)对比条形图(bar plot comparision of mean with different years)
  5. R语言ggplot2可视化自定义多个图例(legend)标签之间的距离实战(例如,改变数据点颜色和数据点大小图例之间的距离)
  6. pandas使用replace函数替换dataframe中的值:replace函数对dataframe中指定数据列的值进行替换、替换具体数据列的相关值
  7. R语言KNN模型数据分类实战
  8. R语言distVincentySphere函数计算大圆距离实战(Great Circle Distance)
  9. python使用imbalanced-learn的ClusterCentroids方法进行下采样处理数据不平衡问题
  10. R使用gbm包构建gbdt模型进行回归分析实战