PAT:1032. Sharing (25) AC

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node
{
  char data;
  int next;
  bool tag;
}Node[100066];

int main()
{
  int add1,add2,n;          //连表1首地址,
  scanf("%d%d%d",&add1,&add2,&n);
  memset(Node,0,sizeof(Node));
  char tmp;
  int from,to;

  for(int i=0 ; i<n ; ++i)        //先把所有结点存入
  {
    scanf("%d %c %d",&from,&tmp,&to);
    Node[from].data=tmp;
    Node[from].next=to;
  }
  int p;
  for(p=add1 ; p!=-1 ; p=Node[p].next)  //【思维】从表1首地址出发,到-1,经过的就是表1所有节点
  {
    Node[p].tag=1;
  }
  for(p=add2 ; p!=-1 ; p=Node[p].next)  //表1到-1走完了,从表2首地址开始,沿着next一直到头
  {
    if(Node[p].tag==1)          //中途有碰到和表一一样的节点,就停止,p记录的就是这个相同结点地址
      break;
  }
  if(p!=-1)          //有地址,按5位格式输出
    printf("%05d",p);
  else            //没有地址,输出-1
    printf("-1");
  //system("pause");
  return 0;
}
时间: 2024-10-06 17:16:16

PAT:1032. Sharing (25) AC的相关文章

PAT Advanced 1032 Sharing(25) [链表]

题目 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 sufix. For example, "loading" and "being" are stored

PAT:1003. Emergency (25) AC

#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; const int MAXV=510; const int INF=0x3fffffff; int n,m,c1,c2; bool vis[MAXV]; int G[MAXV][MAXV]; //城市间距离 int weight[MAXV]; //每个城市的救援人数 int d[MAXV]; //最短距离 int w

PAT:1029. Median (25) AC

#include<stdio.h> #include<algorithm> using namespace std; int arr1[1000066]; int arr2[1000066]; int main() { int n1,n2; scanf("%d",&n1); for(int i=0 ; i<n1 ; ++i) { scanf("%d",&arr1[i]); } scanf("%d",&

PAT:1020. 月饼 (25) AC

#include<stdio.h> #include<algorithm> using namespace std; struct cake { double amount; double sum_price,price; }M[1010]; bool cmp(cake a,cake b) { return a.price>b.price; } int main() { double need=0; int kinds=0; scanf("%d%lf",&

PAT:1070. Mooncake (25) AC

#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; struct moomcake { double store; //[cation]这个可能是小数! double sumPrice; double solePrice; }M[1010]; bool cmp(moomcake a,moomcake b) { return a.solePrice>b.soleP

【PAT甲级】1032 Sharing (25分)

1032 Sharing (25分) 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 a

1032. Sharing (25)【链表】——PAT (Advanced Level) Practise

题目信息 1032. Sharing (25) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B 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.

PAT 1032. Sharing (25)

1032. Sharing (25) 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

PAT:1032. 挖掘机技术哪家强(20) AC

#include<stdio.h> #include<stdlib.h> #include<string.h> #include<algorithm> using namespace std; int arr[100010]; int main() { memset(arr,0,sizeof(arr)); int n,len=0,max=0,maxI=0; scanf("%d",&n); for(int i=0 ; i<n