2009

#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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值