• poj1057


    简单题

    View Code
    #include <iostream>
    #include
    <cstdio>
    #include
    <cstdlib>
    #include
    <cstring>
    #include
    <algorithm>
    using namespace std;

    int dcount;
    int n;
    char word[1005][50];
    int father[1005];
    int fa;
    int dir[1005][1005];
    int num[1005];
    int id[1005];

    void ins(char *st)
    {
    if (strcmp(st, "]") == 0)
    {
    fa
    = father[fa];
    return;
    }
    if (st[0] == 'f')
    {
    dir[fa][num[fa]
    ++] = n;
    return;
    }
    father[dcount]
    = fa;
    id[dcount]
    = n;
    fa
    = dcount++;
    }

    bool cmp(const int &a, const int &b)
    {
    return strcmp(word[a], word[b]) < 0;
    }

    void print(int a, int d)
    {
    for (int i = 0; i < a; i++)
    printf(
    "| ");
    printf(
    "%s\n", word[id[d]]);
    for (int i = d + 1; i < dcount; i++)
    if (father[i] == d)
    print(a
    + 1, i);
    for (int i = 0; i < num[d]; i++)
    {
    for (int j = 0; j < a; j++)
    printf(
    "| ");
    printf(
    "%s\n", word[dir[d][i]]);
    }
    }

    int main()
    {
    //freopen("t.txt", "r", stdin);
    strcpy(word[0], "ROOT");
    int t = 0;
    while (scanf("%s", word[1]), strcmp("#", word[1]) != 0)
    {
    t
    ++;
    memset(num,
    0, sizeof(num));
    dcount
    = 1;
    n
    = 1;
    fa
    = 0;
    father[
    0] = -1;
    ins(word[n]);
    while (scanf("%s", word[++n]), strcmp("*", word[n]) != 0)
    ins(word[n]);
    for (int i = 0; i < dcount; i++)
    sort(dir[i], dir[i]
    + num[i], cmp);
    printf(
    "DATA SET %d:\n", t);
    print(
    0, 0);
    putchar(
    '\n');
    }
    return 0;
    }
  • 相关阅读:
    人工智能数学基础笔记(上)
    人工智能简介
    十三,十四 基金收益,税收与基金国际化
    资产配置模型之-BL模型
    十二 基金估值,费用与会计核算
    十一 基金的投资交易与结算
    十 基金业绩评价
    九 投资风险管理
    浙工商oj ___飞龙的飞行方程
    hd1004解题思路
  • 原文地址:https://www.cnblogs.com/rainydays/p/2116572.html
Copyright © 2020-2023  润新知