紙牌函數生成器

此模板用來生成紙牌類的測試數據,本人手打,不合理或綴餘的地方希望大神指出。

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;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章