纸牌函数生成器

来源:互联网 发布:淘宝网卖家客服 编辑:程序博客网 时间:2024/05/17 03:22

此模板用来生成纸牌类的测试数据,本人手打,不合理或缀余的地方希望大神指出。

T=10000(测试数据组数),

t (两摞相等的牌,每摞牌的数量);

每张牌用A,2~9,T,J,Q,K;表示牌面大小;

用S,H,C,D;表示花色。

共52张牌。

#include<stdio.h>#include<time.h>#include<stdlib.h>#include<string.h>#include<set>using namespace std;int num[10000];char p,h;void zhuanhua(int a,int b){    if(a==1)        p='A';    if(a>=2&&a<=9)        p='0'+a;    if(a==10)        p='T';    if(a==11)        p='J';    if(a==12)        p='Q';    if(a==13)        p='K';    if(b==4)        h='C';    if(b==1)        h='D';    if(b==2)        h='H';    if(b==3)        h='S';}int main(){    freopen("a.txt","w",stdout);    srand((unsigned)time(NULL));    int T=10000;    while(T--)    {        memset(num,0,sizeof(num));        int t=rand()% 26+1;        printf("%d\n",t);        int m=t;        while(t)        {            int a=rand()%13+1;            int b=rand()%4+1;            int c=a*10+b;            if(!num[c])            {                num[c]=1;                t--;                zhuanhua(a,b);                printf("%c%c",p,h);                if(t)                printf(" ");                else                printf("\n");            }        }        t=m;        while(t)        {            int a=rand()%13+1;            int b=rand()%4+1;            int c=a*10+b;            if(!num[c])            {                num[c]=1;                t--;                zhuanhua(a,b);                printf("%c%c",p,h);                if(t)                printf(" ");                else                printf("\n");            }        }    }    return 0;}


0 0
原创粉丝点击