hiho week 78 register

Ended

Participants:288

Verdict:Accepted
Score:100 / 100
Submitted:2015-12-28 15:41:22

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int cnt = 0;
struct TireNode {
    char ch;
    int cnt = 0;
    vector<TireNode*> child;
};
void insert(string str, TireNode* &head) {
    TireNode* p = head;
    for (char ch : str) {
        bool flag = false;
        auto it = p->child.begin();
        for (; it != p->child.end(); ++it) {
            if ((*it)->ch == ch) {
                (*it)->cnt++;
                p = (*it);
                flag = true;
                break;
            }
        }
        if (!flag) {
            TireNode* tmp = new TireNode;
            tmp->ch = ch;
            tmp->cnt++;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX