好吧,注意有可能存在空串,别的就没什么了,代码写的比较烂,有好多不必要的重复。
1 #include2 struct Node{ 3 int next_num; 4 char ch; 5 }; 6 7 struct Node nodes[100002]; 8 int main() 9 {10 int head1,head2,node_num;11 scanf("%d%d%d",&head1,&head2,&node_num);12 int i;13 for(i=0;i len2) {41 max=len1;42 } else {43 max=len2;44 }45 }46 47 if(max==len1) {48 int dif=len1-len2;49 while(dif--) {50 head1=nodes[head1].next_num;51 }52 } else {53 int dif=len2-len1;54 while(dif--) {55 head2=nodes[head2].next_num;56 }57 }58 //now aligned59 60 while(head1!=-1&&head2!=-1) {61 if(head1==head2) {62 printf("%05d\n",head1);63 return 0;64 }65 head1=nodes[head1].next_num;66 head2=nodes[head2].next_num;67 }68 printf("-1\n");69 return 0;70 }