PAT 甲级 1032 Sharing
发布日期:2021-07-01 03:09:01 浏览次数:2 分类:技术文章

本文共 2404 字,大约阅读时间需要 8 分钟。

1032 Sharing (25 point(s))

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 beingare stored as showed in Figure 1.

fig.jpg

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 (≤10​5​​), 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

whereAddress 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 967890 i 0000200010 a 1234500003 g -112345 D 6789000002 n 0000322222 B 2345611111 L 0000123456 e 6789000001 o 00010

Sample Output 1:

67890

Sample Input 2:

00001 00002 400001 a 1000110001 s -100002 a 1000210002 t -1

Sample Output 2:

-1

Experiential Summing-up

This question used to appear in 408 algorithm's problem. That is search two words' common suffix which stored by linklist. It's not too hard. See the code for details.

(The purpose of using English to portray my solution is that to exercise the ability of my expression of English and accommodate PAT advanced level's style.We can make progress together by reading and comprehending it. Please forgive my basic grammar's and word's error. Of course, I would appreciated it if you can point out my grammar's and word's error in comment section.( •̀∀•́ ) Furthermore, Big Lao please don't laugh at me because I just a English beginner settle for CET6    _(:з」∠)_  )

Accepted Code

#include 
#include
#include
#include
using namespace std;const int maxn=100010;const int INF=0x3fffffff;struct node{ int next; char data; int flag; node() { flag=0; }}Node[maxn];int main(){ int f,s,n,t; scanf("%d %d %d",&f,&s,&n); for(int i=0;i

 

转载地址:https://meteorrain.blog.csdn.net/article/details/86605921 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:PAT 甲级 1033 To Fill or Not to Fill
下一篇:PAT 甲级 1031 Hello World for U

发表评论

最新留言

表示我来过!
[***.240.166.169]2024年04月15日 07时27分39秒