POJ 3283 Card Hands

/*

http://acm.pku.edu.cn/JudgeOnline/problem?id=3283

Trie树,最终插入的结点的数量
状态不好写code就是恶心,这么简单的题,犯了那么多恶心的错误
*/
#include <iostream>
#define MAX_N 100100
using namespace std;

int trieTree[MAX_N + 1][13][4];
int countv, total;

char temp[60][5];

void getP(char * const & temp, int &p1, int &p2)
{
    char c1, c2;
    if(strlen(temp) == 3)
    {
        p1 = 9;
        c2 = temp[2];
    }
    else
    {
        c1 = temp[0];
        c2 = temp[1];
    }
    if(strlen(temp) != 3)
    {
        if(c1 >= '2' && c1 <= '9')
            p1 = c1 - '1';
        else
        {
            if(c1 == 'A')
                p1 = 0;
            else if(c1 == 'J')
                p1 = 10;
            else if(c1 == 'Q')
                p1 = 11;
            else
                p1 = 12;
        }
    }
    if(c2 == 'C')
        p2 = 0;
    else if(c2 == 'D')
        p2 = 1;
    else if(c2 == 'H')
        p2 = 2;
    else
        p2 = 3;
}
void insert()
{
    int sLen, i, p1, p2;
    cin>>sLen;
    for(i = 0; i < sLen; i++)
        scanf("%s", temp[i]);
    int curPos = 0, next;
    for(i = sLen - 1; i >= 0; i--)
    {
        getP(temp[i], p1, p2);
        next = trieTree[curPos][p1][p2];
        if(next == 0)
        {
            trieTree[curPos][p1][p2] = next = ++countv;
            total++;
        }
        curPos = next;
    }
}
int main()
{
    int listNum, c;
    while(scanf("%d", &listNum) && listNum != 0)
    {
        memset(trieTree, 0, sizeof(trieTree));
        countv = total = 0;
        for(c = 0; c < listNum; c++)
            insert();
        cout<<total<<endl;
    }
    return 0;
}

你可能感兴趣的:(c,insert)