我发现字母根本不用管它,所以结构体只写入了地址
#include<iostream>
using namespace std;
const int maxn = 100010;
struct NODE {
int next;
bool flag;
char data;
NODE():flag(false){}
}node[maxn];
int main() {
int a, b, c;
cin >> a >> b >> c;
int adress,next;
char data;
for (int i = 0;i < c;i++) {
cin >> adress >> data >> next;
node[adress].next = next;
}
int p;
for (p = a;p != -1;p = node[p].next) {
node[p].flag = true;
}
for (p = b;p != -1;p = node[p].next) {
if (node[p].flag == true) {
printf("%05d", p);
return 0;
}
}
cout << "-1";
return 0;
}