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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
using namespace std; typedef struct node { int data; struct node* l, * r; }BiTode, * BiTree; BiTree t1, t2; int flag; BiTree insert(BiTree t, int x) { if (t == NULL) { t = (struct node*)malloc(sizeof(struct node)); t->data = x; t->l = NULL; t->r = NULL; } else if (x < t->data) { t->l = insert(t->l, x); } else { t->r = insert(t->r, x); } return t; } BiTree creat(char a[], int n) { int j = 0; BiTree t = NULL; while (j < n) { t = insert(t, a[j] - '0'); j++; } return t; } int compare(BiTree t1, BiTree t2) { if (t1 == NULL && t2 == NULL) { return 1; } else if (t1 == NULL || t2 == NULL) { flag = 0; return 0; } else if (t1->data != t2->data) { flag = 0; return 0; } else return compare(t1->l, t2->l) && compare(t1->r, t2->r); } int main() { int n, len; char a[11], b[11]; //while (scanf("%d", &n) != EOF && n) while(cin>>n&&n) {
//scanf("%s", a); cin >> a; len = strlen(a);//strlen的参数只能是char 类型 t1 = creat(a, len); while (n--) { //scanf("%s", b); cin >> b; t2 = creat(b, len); flag = 1; compare(t1, t2); if (flag == 1) printf("YES\n"); else printf("NO\n"); } } return 0;
}
|