栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 3283 Card Hands

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 3283 Card Hands

#include <iostream>#include <stdio.h>#include <stack>#include <string>using namespace std;const int n=53;struct node{    node *next[n];    node()    {        int i;        for(i=0;i<n;i++) next[i]=NULL;    }};node *root,*p;int res;int hash(string s)   //传说中的hash{    int temp=0;    if(s[1]=='0')    {        if(s[2]=='C') temp+=13*0;        else if(s[2]=='D') temp+=13*1;        else if(s[2]=='H') temp+=13*2;        else temp+=13*3;        return temp+=10;    }    if(s[1]=='C') temp+=13*0;    else if(s[1]=='D') temp+=13*1;    else if(s[1]=='H') temp+=13*2;    else temp+=13*3;    switch(s[0])    {        case 'A': temp+=1;break;        case 'J': temp+=11;break;        case 'Q': temp+=12;break;        case 'K': temp+=13;break;        default :temp+=s[0]-'0';break;    }    return temp;}void Insert(int num){    if(p->next[num]==NULL)    {        p->next[num]=new node();        res++;    }    p=p->next[num];}void Delete(node *t){    int i;    for(i=0;i<n;i++)    {        if(t->next[i]!=NULL) Delete(t->next[i]);        t->next[i]=NULL;    }    delete t;}int main(){    int num,m,i,j;    string str;    stack<string> s;    while(scanf("%d",&num) && num!=0)    {        res=0;        root=new node();        for(i=0;i<num;i++)        { scanf("%d",&m); for(j=0;j<m;j++) {     cin>>str;     s.push(str); } p=root; while(!s.empty()) {     int value=hash(s.top());     s.pop();     Insert(value); }        }        printf("%dn",res);        Delete(root);    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/377600.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号