PAT 1032

题目 : Sharing

分值 : 25
难度 : 简单题
思路 : 题目给链表地址 5位数  让你自己搞个链表 傻子才真弄个链表给你
坑点 : 给个屁链表啊,直接数组下标寻址就好了
评语 : cin cout 耗时有点长

具体代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
using namespace std ;
typedef struct Node{
int add;
int next ;
}Nodes ;
Nodes data[100000];
int flag[100000];
int main() {
int S ,D ,N ;
cin >> S>>D>>N ;
for(int i = 0 ; i < N ; i++)
{
int add,next ;
char ch ;
scanf("%d %c %d",&add,&ch ,&next);
data[add].add= add ;
data[add].next = next ;
}
int cur = S ;
while(cur!=-1)
{
flag[cur] ++ ;
cur = data[cur].next;
}
cur = D;
while(cur!=-1)
{
if(flag[cur]) {
printf("%05d\n",cur) ;
break ;
}
cur = data[cur].next ;
}
if(cur==-1)
cout<<cur<<endl ;
return 0;
}