#include<iostream>
#include<algorithm>
using namespace std;
int m;
bool wanshu(int a) {
int sum = 0;
for (int i = 1; i < a; i++) {
if (a%i == 0) {
sum += i;
}
}
if (sum == a) return true;
else return false;
}
bool su(int b) {
for (int i = 2; i < b; i++) {
if (b%i == 0) return 0;
}
return 1;
}
int yinzi(int a) {
int count;
if (a == 1) {
return 1;
}
else if (a == 2) {
return 2;
}
else {
for (int i = 2; i < a; i++) {
if (a%i == 0) {
count = i;
}
}
return count;
}
}
struct node {
char value;
node* lchild;
node* rchild;
node(char ch) {
value = ch;
lchild = rchild = NULL;
}
};
node* bulidTree(string pre, string in) {
int len = pre.size();
if (len <= 0) return NULL;
node* root = new node(pre[0]);
int p = in.find(pre[0]);
root->lchild = bulidTree(pre.substr(1, p), in.substr(0, p));
root->rchild = bulidTree(pre.substr(p + 1, len - p - 1), in.substr(p + 1, len - p - 1));
return root;
}
void postOrder(node* root) {
if (root->lchild) postOrder(root->lchild);
if (root->rchild) postOrder(root->rchild);
cout << root->value;
}
int main() {
//2009 Problems A 求完数
/*int a, b,numbers[100000],count=0;
bool s=false;
cin >> a >> b;
for (int i = a; i <= b; i++) {
s = wanshu(i);
if (s == true) {
numbers[count] = i;
count++;
}
}
for (int j = 0; j < count; j++) {
printf("%d\n", numbers[j]);
}*/
//2009 Problems B 矩阵求和
/*int m,numbers[10][10],n[22],count=0,sum;
cin >> m;
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
cin >> numbers[i][j];
}
}
for (int i = 0; i < m; i++) {
sum = 0;
for (int j = 0; j < m; j++) {
sum += numbers[i][j];
}
n[count] = sum;
count++;
}
for (int j = 0; j < m; j++) {
sum = 0;
for (int i = 0; i < m; i++) {
sum += numbers[i][j];
}
n[count] = sum;
count++;
}
sum = 0;
for (int i = 0; i < m; i++) {
sum += numbers[i][i];
}
n[count] = sum;
count++;
sum = 0;
for (int i = 0; i < m; i++) {
sum += numbers[i][m - i - 1];;
}
n[count] = sum;
count++;
for (int i = 0; i < count; i++) {
cout<< n[i]<<" ";
}
printf("\n");
sort(n,n+count);
for (int i = count-1; i >=0; i--) {
cout << n[i] << " ";
}
printf("\n");*/
//2009 Problems C 提取整数
/*int count, num = 0, s;
cin >> count;
char cha[100];
for (int i = 0; i < count; i++) {
memset(cha, 0, 100);
scanf_s("%s", &cha, sizeof(cha));
printf("%s\n", cha);
for (int j = 0;; j++) {
if (cha[j] == '\0') break;
if (cha[j] >= '0'&&cha[j] <= '9') {
num *= 10;
s = (int)cha[j] - 48;
num += s;
}
}
//printf("%d\n", num);
if (su(num) == 1) {
cout << num << endl;
}
else {
cout << yinzi(num) << endl;
}
num = 0;
}*/
//2009 Problems E 括号匹配
/*int count;
cin >> count;
for (int k = 0; k < count; k++) {
char stack[100],stack1[100];
scanf_s("%s",stack,sizeof(stack));
int n = 1,i=0,j=0;
bool flag = 0;
while (n != 0) {
if ((stack[i] == NULL)&&j==0) {
flag = 1;
break;
}
if ((stack[i] == '[')|| (stack[i] == '(') || (stack[i] == '{')) {
stack1[j] = stack[i];
j++;
}
else if ((stack[i] == ']') || (stack[i] == ')') || (stack[i] == '}')) {
if (stack[i] == ']') {
if (stack1[j - 1] == '[') {
stack1[j - 1] = NULL;
j--;
}
else
break;
}
else if (stack[i] == ')') {
if (stack1[j - 1] == '(') {
stack1[j - 1] = NULL;
j--;
}
else
break;
}
else if (stack[i] == '}') {
if (stack1[j - 1] == '{') {
stack1[j - 1] = NULL;
j--;
}
else
break;
}
}
i++;
}
printf("%d\n",flag);
}*/
//2009 Problems D 树先序中序求后序
/*char pre[100] = "ABDGCEFH", in[100] = "DGBAECHF";
node* root = bulidTree(pre, in);
postOrder(root);*/
return 0;
}