#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <cmath>
using namespace std;
/*
链表题

*/
int n; struct Word{
int addr;
char ch;
int next=-;
}word[];
int vis[];
int main()
{
int first1,first2;
int adr,nxt;
char ch;
scanf("%d %d %d",&first1,&first2,&n);
for(int i=;i<n;i++){
scanf("%d %c %d",&adr,&ch,&nxt);
word[adr].addr=adr;
word[adr].ch=ch;
word[adr].next=nxt;
}
memset(vis,,sizeof(vis));
while(first1!=-){
vis[first1]=;
first1=word[first1].next;
}
bool flag=false;
while(first2!=-){
if(vis[first2]){
flag=true;
break;
}
first2=word[first2].next;
}
if(flag)
printf("%05d\n",first2);
else
printf("-1\n");
return ;
}

PAT甲题题解-1032. Sharing (25)-链表水题的更多相关文章

  1. PAT甲题题解-1041. Be Unique (20)-水题

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789189.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  2. PAT甲题题解-1050. String Subtraction (20)-水题

    #include <iostream> #include <cstdio> #include <string.h> #include <algorithm&g ...

  3. PAT甲题题解-1120. Friend Numbers (20)-水题

    博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789775.html特别不喜欢那些随便转载别人的原创文章又不给 ...

  4. PAT Advanced 1032 Sharing(25) [链表]

    题目 To store English words, one method is to use linked lists and store a word letter by letter. To s ...

  5. PAT甲 1032. Sharing (25) 2016-09-09 23:13 27人阅读 评论(0) 收藏

    1032. Sharing (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To store Engl ...

  6. PAT 甲级 1032 Sharing (25 分)(结构体模拟链表,结构体的赋值是深拷贝)

    1032 Sharing (25 分)   To store English words, one method is to use linked lists and store a word let ...

  7. PAT 1032 Sharing[hash][链表][一般上]

    1032 Sharing (25)(25 分) To store English words, one method is to use linked lists and store a word l ...

  8. 【PAT】1032 Sharing (25)(25 分)

    1032 Sharing (25)(25 分) To store English words, one method is to use linked lists and store a word l ...

  9. 1032 Sharing (25分)

    1032 Sharing (25分) 题目 思路 定义map存储所有的<地址1,地址2> 第一set存放单词1的所有地址(通过查找map) 通过单词二的首地址,结合map,然后在set中查 ...

随机推荐

  1. nginx 服务器在上传文件出现413代码的解决方法

    打开nginx主配置文件nginx.conf 找到http{}段,添加client_max_body_size 20m;

  2. Python datetime.md

    datetime datetime模块包含了一些用于时间解析.格式化.计算的函数. Times 时间值由time类来表示, Times有小时, 分, 秒和微秒属性. 以及包含时区信息. 初始化time ...

  3. json 压缩中文不转码

    $testJSON=array('name'=>'中文字符串','value'=>'test'); echo json_encode($testJSON, JSON_UNESCAPED_U ...

  4. java读写properties配置文件方法

    1.Properties类 Properties类表示了一个持久的属性集.Properties可保存在流中或从流中加载,属性列表中的key和value必须是字符串. 虽然Properties类继承了j ...

  5. 基于VC++ Win32+CUDA+OpenGL组合与VC++ MFC SDI+CUDA+OpenGL组合两种方案的遥感影像显示:获得的重要结论!

    1.基于VC++ Win32+CUDA+OpenGL组合的遥感影像显示 在该组合方案下,初始化时将OpenGL设置为下面两种方式,效果一样 //设置方式1 glutInitDisplayMode (G ...

  6. vmware中装的ubuntu上不了网

    背景 上周末重装了windows主机的系统,之后就重新安装了vmware软件,今天使用的时候就发现git pull代码仓库的时候,发现代码仓库无法获取,检查后发现是虚拟机上不了网了. 查看了一系列教程 ...

  7. E - A Twisty Movement

    A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with ba ...

  8. P2176 [USACO14FEB]路障Roadblock

    题目描述 每天早晨,FJ从家中穿过农场走到牛棚.农场由 N 块农田组成,农田通过 M 条双向道路连接,每条路有一定长度.FJ 的房子在 1 号田,牛棚在 N 号田.没有两块田被多条道路连接,以适当的路 ...

  9. c++ 模板参数做容器参数迭代器报错 vector<T>::const_iterator,typename const报错

    错误1: template<class T>void temp(std::vector<T>& container){        std::vector<T& ...

  10. R 语言的Dataframe常用操作

    上节我们简单介绍了Dataframe的定义,这节我们具体来看一下Dataframe的操作 首先,数据框的创建函数为 data.frame( ),参考R语言的帮助文档,我们来了解一下data.frame ...