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

zoj 2409 A Card Trick

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

zoj 2409 A Card Trick

#include<iostream>#include<string.h>#include<algorithm>#include<stdio.h>using namespace std;enum {    SIZ = 5,};string vlist[] = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};string tlist[] = {"C","D","H","S"};struct Node {    int val;    int type;    bool operator < (const Node&rhs)const {        if(val != rhs.val) return val < rhs.val;        return type<rhs.type;        }  };Node tree[SIZ];int find(string l[], string & v){    int r = 0;    while(strcmp(l[r].c_str(), v.c_str())!=0){        r++;    }    r++;    return r;}void readIn(){    string s;    for(int i=0;i<SIZ;i++){        string tm;        cin>>s;        tm += s[s.length()-1];        tree[i].type = find(tlist, tm);        s[s.length()-1] = 0;        tree[i].val = find(vlist, s);    }}bool check(){    if(tree[0].type != tree[1].type){        return false;    }    int v = 1;    for(int i=2;i<4;i++){        if(tree[1+i] < tree[1+v]){ v = i;        }    }    if(v == 1){        if(tree[4] < tree[3]) { v += 3;        }    } else if(v==2){        if(tree[4] < tree[2]){ v += 3;        }    } else {        if(tree[3] < tree[2]){ v += 3;        } }    v += tree[1].val;    v--;    v %= 13;    v ++;    return v == tree[0].val;}int fun(){    static int tst = 0;        cout<<"Problem "<<++tst<<": ";    sort(tree, tree+SIZ);    while(!check()){        next_permutation(tree, tree+SIZ);    }    cout<<vlist[tree[0].val-1]<<tlist[tree[0].type-1];    for(int i=1;i<SIZ;i++){        cout<<" "<< vlist[tree[i].val-1]<<tlist[tree[i].type-1];    }    cout<<endl;}int main(){    int tstcase;    cin>>tstcase;    while(tstcase --){        readIn();        fun();    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/372051.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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