文章
7
粉丝
502
获赞
2
访问
17.1k
正确输出应该是YES和NO,不知道是哪里出了差错
- #include<iostream>
- #include<stdio.h>
- #include<cstring>
- #include<algorithm>
- using namespace std;
-
- bool judge(int s1[], int s2[], int x , int y)
- {
- if (x != y) return false;
- if (x == 0 && y == 0) return true;
- if (s1[0] != s2[0]) return false;
- else
- {
- int ls1[10], rs1[10], ls2[10], rs2[10];
- int j = 0, k = 0, l = 0, m = 0;
- for (int i = 1; i < x; i++)
- {
- if (s1[i] < s1[0])//小于根节点的值放入左子树
- ls1[j++] = s1[i];
- else rs1[k++] = s1[i];
- }
- for (int i = 1; i < y; i++)
- {
- if (s2[i] < s2[0])
- ls2[l++] = s2[i];
- else rs2[m++] = s2[i];
- }
- return judge(ls1, ls2, j, k) && judge(rs1, rs2, l, m);
- }
- }
-
- int main()
- {
- int n;
- int snum[10], ssnum[10];
- while (cin >> n)
- {
- if (n == 0) break;
- string s;
- cin >> s;
- int len = s.size();
- for (int i = 0; i < len; i++)
- snum[i] = s[i] - '0';//类型转化
- for (int i = 0; i &l...
登录后发布评论
暂无评论,来抢沙发