pat1032 Sharing
来源:互联网 发布:骰子php源码 编辑:程序博客网 时间:2024/05/22 07:55
#include<cstdio>#include<iostream>#include<algorithm>#include<vector>#include<queue>#include<string>#include<cstring>#include<cmath>#include<map>#define ll long longusing namespace std;struct node{char key;int next;}p[1000005];int main(){char c;int n,b1,b2,l1,l2,i,j,x,y,ans;while(scanf("%d%d%d",&b1,&b2,&n)!=EOF){l1 = l2 = 0;for(i = 1;i<=n;i++){scanf("%d %c %d",&x,&c,&y);p[x].key = c;p[x].next = y;}i = b1;while(i!=-1){i = p[i].next;l1++;}i = b2;while(i!=-1){i = p[i].next;l2++;}if(l1>l2)for(i = 0;i<l1-l2;i++)b1 = p[b1].next;else for(i = 0;i<l2-l1;i++)b2 = p[b2].next;int f = 0;while(b1!=-1){if(b1 == b2){ans = b1;f = 1;break;}b1 = p[b1].next;b2 = p[b2].next;}if(f)printf("%05d\n",ans);else printf("-1\n");} return 0;}
0 0
- pat1032 Sharing
- [哈希]PAT1032 Sharing
- pat1032
- PAT1032
- 【PAT1032】Sharing 找两单词链表的相同后缀
- sharing
- Sharing
- Sharing
- Sharing
- PAT1032 挖掘机技术哪家强
- PAT1032挖掘机技术哪家强
- pat1032:挖掘机技术哪家强
- PAT1032 挖掘机技术哪家强(20)
- runtime sharing
- Internal sharing
- Sharing Resources
- Sharing chocolate
- 1032:Sharing
- 日记
- V-Ray Adv for 3dsmax 2012 for x86安装
- ZOJ 3203 Light Bulb
- Object-C Category(OC分类)
- 【Puppet2D】实践2
- pat1032 Sharing
- HDU 2276解题报告
- OC点语法
- POJ 2079 旋转卡壳
- Codeforces Round #286 (Div. 2) D.
- UVALive 4126 Password Suspects(AC自动机+dp)
- 再思如何做好一个好的网站
- ZOJ 3204 Connect them
- MyBatis学习(二)