zoukankan      html  css  js  c++  java
  • hdu 1504蛋疼的模拟

    蛋疼的题目,测试数据都没说清楚,都想骂出题人了。细节部分好理解,就是模拟,打完以后不敢交,不知道测试数据中的1是啥,上网搜解题报告,居然没有,再一看过题数,63,我了个去。。。无奈只好自己试了,试了几次后发现1是测试数据总数。。。瀑布汗。。。

    /*
     * hdu1504/win.cpp
     * Created on: 2012-7-31
     * Author    : ben
     */
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <set>
    #include <map>
    #include <stack>
    #include <string>
    #include <vector>
    #include <deque>
    #include <list>
    #include <functional>
    #include <numeric>
    #include <cctype>
    using namespace std;
    const int MAXN = 505;
    const int MAXLEN = 85;
    const int MAXNODE = 10000;
    typedef struct TreeNode{
        char word[MAXLEN];
        int childnum;
        TreeNode *child[MAXN];
        void init() {
            memset(word, 0, sizeof(word));
            memset(child, 0, sizeof(child));
            childnum = 0;
        }
        void init(const char *str) {
            init();
            strcpy(word, str);
        }
        TreeNode() {
            init();
        }
    }TreeNode;
    typedef struct TreeNode* TreeLink;
    TreeNode root[MAXNODE];
    int N, cur;
    inline TreeNode* newNode(const char *str) {
        root[cur].init(str);
        return &root[cur++];
    }
    TreeNode* myinsert(TreeNode *node, const char* str) {
        for(int i = 0; i < node->childnum; i++) {
            if(strcmp(node->child[i]->word, str) == 0) {
                return node->child[i];
            }
        }
        node->child[node->childnum] = newNode(str);
        return node->child[node->childnum++];
    }
    int work(char *str) {
        char *p = strtok(str, "\\");
        TreeNode *cur = root;
        while(p) {
            cur = myinsert(cur, p);
            p = strtok(NULL, "\\");
        }
        return 0;
    }
    inline bool cmp(const TreeLink &tl1, const TreeLink &tl2) {
        return strcmp(tl1->word, tl2->word) < 0;
    }
    void myprint(TreeNode *node, int bnum) {
        sort(node->child, node->child + node->childnum, cmp);
        if(node != root) {
            for(int i = 0; i < bnum; i++) {
                putchar(' ');
            }
            puts(node->word);
        }
        for(int i = 0; i < node->childnum; i++) {
            myprint(node->child[i], bnum + 1);
        }
    }
    
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("data.in", "r", stdin);
    #endif
        int T;
        char str[200];
        scanf("%d", &T);
        for(int t = 0; t < T; t++) {
            scanf("%d", &N);
            cur = 1;
            root[0].init();
            for(int i = 0; i < N; i++) {
                scanf("%s", str);
                work(str);
            }
            myprint(root, -1);
            if(t != T - 1) {
                putchar('\n');
            }
        }
        return 0;
    }
  • 相关阅读:
    项目实战
    bootscript/javascript组件
    html5应用程序标签
    bootstrap框架应用
    bootstrap javascript插件部分的笔记整理
    bootstrap页面模板
    redis安装
    nginx + vsftpd 搭建 图片服务器
    centOs7 安装
    单链表的最装逼写法
  • 原文地址:https://www.cnblogs.com/moonbay/p/2617593.html
Copyright © 2011-2022 走看看