| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 443 人关注过本帖
标题:发牌程序求高手支招 。。。。。谢谢。
只看楼主 加入收藏
loveshuang
Rank: 9Rank: 9Rank: 9
来 自:湖北武汉
等 级:蜘蛛侠
帖 子:270
专家分:1198
注 册:2010-11-14
结帖率:100%
收藏
 问题点数:0 回复次数:3 
发牌程序求高手支招 。。。。。谢谢。
#include <iostream>
#include <string>
using namespace std;

class card
{
public:
    card(){}
    void put(int x[],int y[],int z[],int w[])
    {
        int i,j=0;
        for(i=0;i<13;i++,j++)
        {
            a[j]=x[i];
            a[j+13]=y[i];
            a[j+26]=z[i];
            a[j+39]=w[i];
        }
    }
    void set(int c[],int n)
    {
        int temp,flag,i,j;
        for(i=0;i<n-1;i++)
        {
            flag=1;
            for(j=1;j<n-i;j++)
                if(c[j]<c[j-1])
                {
                    temp=c[j-1];
                    c[j-1]=c[j];
                    c[j]=temp;
                    flag=0;
                }
                if(flag==1)
                    break;
        }
    }
    void get(int b[],int n)
    {
        for(int i=0;i<n;i++)
            switch(b[i])
            {
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
    cout<<b[i]<<' ';break;
case 11:
    cout<<'J'<<' ';break;
case 12:
    cout<<'Q'<<' ';break;
case 13:
    cout<<'K'<<' ';break;
case 14:
    cout<<'A'<<' ';break;
            }
            cout<<'\n';
    }
   
   
protected:
    int a[52];
};

class bridge:public card
{
public:
    bridge(){}
    bridge(int g){put(m,n,k,h);}
    void deal()
    {
        int i,j=0;
        for(i=0;i<13;j+=4,i++)
        {
            m[i]=a[j];
            n[i]=a[j+1];
            k[i]=a[j+2];
            h[i]=a[j+3];
        }
    }
   
    void get1()
    {
        set(m,13);
        cout<<"爽哥:";
        get(m,13);
        set(n,13);
        cout<<"胖子:";
        get(n,13);
        set(k,13);
        cout<<"猪头:";
        get(k,13);
        set(h,13);
        cout<<"马子:";
        get(h,13);
    }
private:
     int m[13],n[13],k[13],h[13];
};

class poker:public card
{
public:
    poker(){}
    poker(int n){
        s=new string[n];
        b=new int[5*n];

        cout<<"输入参加者的名字"<<endl;
        for(int i=0;i<n;i++)
            cin>>s[i];
    }
    void deal(int n)
    {
        int i,j=0;
        for(i=1;i<=n;i++)
        {
            for(;j<i*5;j++)
                b[j]=a[2*j/52];
            j+=5;
        }
    }
    void get2(int n)
    {
        int i,j=0;
        int* p;
        p=new int[n];
        for(i=0;i<n;i++)
        {
            cout<<s[i]<<':';
            for(0;j<(i+1)*5;j++)
            {
                p[i]+=b[j];
                cout<<b[j];
            }
            j+=5;
                cout<<'    '<<"总点数为:"<<p[i]<<endl;
        }
    }
private:
    int* b;
    string* s;
};

void main()
{
    int a[13]={2,3,4,5,6,7,8,9,10,11,12,13,14};
    int b[13]={14,13,12,11,10,9,8,7,6,5,4,3,2};
    int c[13]={8,7,6,5,4,3,2,9,10,11,12,13,14};
    int d[13]={8,9,10,11,12,13,14,7,6,5,4,3,2};

    card s1;
    s1.put(a,b,c,d);
    bridge s2;
    s2.deal();
    char s;
    do
    {
        cout<<"***洗牌***"<<endl;
        bridge s3(4);
        s3.deal();
        cout<<"是否发牌,按y或n"<<endl;
        if(getchar()=='y')
            s3.get1();
        
        cout<<"继续娱乐请按n"<<endl;
        cin>>s;
    }while(s=='n');
   
    int n;
    do
    {
        cout<<"输入参加人数"<<endl;
        cin>>n;
        cout<<"***洗牌***"<<endl;
        poker s4(n);
        s4.deal(n);
        cout<<"是否发牌,按y或n"<<endl;
        if(getchar()=='y')
            s4.get2(n);
        else
            break;
        cout<<"继续娱乐请按回车"<<endl;
    }while(getchar()=='\n');
}

为什么运行没错但是没有结果输出呢?求帮忙按这种发牌的方式把这个程序解决一下,能正常的发牌。谢谢了。





搜索更多相关主题的帖子: 发牌 
2010-11-15 17:17
m21wo
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:4
帖 子:440
专家分:1905
注 册:2010-9-23
收藏
得分:0 
程序代码:
#include <iostream>
#include <string>
using namespace std;

class card
{
public:
    card(){}
    void put(int x[],int y[],int z[],int w[])
    {
        int i,j=0;
        for(i=0;i<13;i++,j++)
        {
            a[j]=x[i];
            a[j+13]=y[i];
            a[j+26]=z[i];
            a[j+39]=w[i];
        }
    }
    void set(int c[],int n)
    {
        int temp,flag,i,j;
        for(i=0;i<n-1;i++)
        {
            flag=1;
            for(j=1;j<n-i;j++)
                if(c[j]<c[j-1])
                {
                    temp=c[j-1];
                    c[j-1]=c[j];
                    c[j]=temp;
                    flag=0;
                }
                if(flag==1)
                    break;
        }
    }
    void get(int b[],int n)
    {
        for(int i=0;i<n;i++)
            switch(b[i])
            {
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
    cout<<b[i]<<' ';break;
case 11:
    cout<<'J'<<' ';break;
case 12:
    cout<<'Q'<<' ';break;
case 13:
    cout<<'K'<<' ';break;
case 14:
    cout<<'A'<<' ';break;
            }
            cout<<'\n';
    }
    

    int a[52];
};

class bridge : public card
{
public:
    bridge(){}
    bridge(int g){put(m,n,k,h);}
    void deal(card s)
    {
        int i,j=0;
        for(i=0;i<13;j+=4,i++)
        {
            m[i]=s.a[j];
            n[i]=s.a[j+1];
            k[i]=s.a[j+2];
            h[i]=s.a[j+3];
        }
    }
   
    void get1()
    {
        set(m,13);
        cout<<"爽哥:";
        get(m,13);
        set(n,13);
        cout<<"胖子:";
        get(n,13);
        set(k,13);
        cout<<"猪头:";
        get(k,13);
        set(h,13);
        cout<<"马子:";
        get(h,13);
    }
private:
     int m[13],n[13],k[13],h[13];
};

class poker:public card
{
public:
    poker(){}
    poker(int n){
        s=new string[n];
        b=new int[5*n];

        cout<<"输入参加者的名字"<<endl;
        for(int i=0;i<n;i++)
            cin>>s[i];
    }
    void deal(int n)
    {
        int i,j=0;
        for(i=1;i<=n;i++)
        {
            for(;j<i*5;j++)
                b[j]=a[2*j/52];
            j+=5;
        }
    }
    void get2(int n)
    {
        int i,j=0;
        int* p;
        p=new int[n];
        for(i=0;i<n;i++)
        {
            cout<<s[i]<<':';
            for(0;j<(i+1)*5;j++)
            {
                p[i]+=b[j];
                cout<<b[j];
            }
            j+=5;
                cout<<'    '<<"总点数为:"<<p[i]<<endl;
        }
    }
private:
    int* b;
    string* s;
};

void main()
{
    int a[13]={2,3,4,5,6,7,8,9,10,11,12,13,14};
    int b[13]={14,13,12,11,10,9,8,7,6,5,4,3,2};
    int c[13]={8,7,6,5,4,3,2,9,10,11,12,13,14};
    int d[13]={8,9,10,11,12,13,14,7,6,5,4,3,2};

    card s1;
    s1.put(a,b,c,d);
    bridge s2;
    s2.deal(s1);
    char s;
    do
    {
        cout<<"***洗牌***"<<endl;
        bridge s3(4);
        s3.deal(s1);
        cout<<"是否发牌,按y或n"<<endl;
        if(getchar()=='y')
            s3.get1();
       
        cout<<"继续娱乐请按n"<<endl;
        cin>>s;
    }while(s=='n');
   
    int n;
    do
    {
        cout<<"输入参加人数"<<endl;
        cin>>n;
        cout<<"***洗牌***"<<endl;
        poker s4(n);
        s4.deal(n);
        cout<<"是否发牌,按y或n"<<endl;
        if(getchar()=='y')
            s4.get2(n);
        else
            break;
        cout<<"继续娱乐请按回车"<<endl;
    }while(getchar()=='\n');
}


If You Want Something, Go Get It, Period.
2010-11-15 18:27
loveshuang
Rank: 9Rank: 9Rank: 9
来 自:湖北武汉
等 级:蜘蛛侠
帖 子:270
专家分:1198
注 册:2010-11-14
收藏
得分:0 
回复 2楼 m21wo
太感谢了,再修改下只能连续的输出了,但是每次的牌是一样的,怎么改进能使每次输出都不一样的呢?
#include <iostream>
#include <string>
using namespace std;

class card
{
public:
    card(){}
    void put(int x[],int y[],int z[],int w[])
    {
        int i,j=0;
        for(i=0;i<13;i++,j++)
        {
            a[j]=x[i];
            a[j+13]=y[i];
            a[j+26]=z[i];
            a[j+39]=w[i];
        }
    }
    void set(int c[],int n)
    {
        int temp,flag,i,j;
        for(i=0;i<n-1;i++)
        {
            flag=1;
            for(j=1;j<n-i;j++)
                if(c[j]<c[j-1])
                {
                    temp=c[j-1];
                    c[j-1]=c[j];
                    c[j]=temp;
                    flag=0;
                }
                if(flag==1)
                    break;
        }
    }
    void get(int b[],int n)
    {
        for(int i=0;i<n;i++)
            switch(b[i])
            {
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
    cout<<b[i]<<' ';break;
case 11:
    cout<<'J'<<' ';break;
case 12:
    cout<<'Q'<<' ';break;
case 13:
    cout<<'K'<<' ';break;
case 14:
    cout<<'A'<<' ';break;
            }
            cout<<'\n';
    }
   

    int a[52];
};

class bridge : public card
{
public:
    bridge(){}
    bridge(int g){put(m,n,k,h);}
    void deal(card s)
    {
        int i,j=0;
        for(i=0;i<13;j+=4,i++)
        {
            m[i]=s.a[j];
            n[i]=s.a[j+1];
            k[i]=s.a[j+2];
            h[i]=s.a[j+3];
        }
    }
   
    void get1()
    {
        set(m,13);
        cout<<"爽哥:";
        get(m,13);
        set(n,13);
        cout<<"胖子:";
        get(n,13);
        set(k,13);
        cout<<"猪头:";
        get(k,13);
        set(h,13);
        cout<<"马子:";
        get(h,13);
    }
private:
     int m[13],n[13],k[13],h[13];
};

class poker:public card
{
public:
    poker(){}
    poker(int n){
        s=new string[n];
        b=new int[5*n];

        cout<<"输入参加者的名字"<<endl;
        for(int i=0;i<n;i++)
            cin>>s[i];
    }
    void deal(card s,int n)
    {
        int i,j=0;
        for(i=1;i<=n;i++)
        {
            for(;j<i*5;j++)
                b[j]=a[2*j/52];
            j+=5;
        }
    }
    void get2(int n)
    {
        int i,j=0;
        int* p;
        p=new int[n];
        for(i=0;i<n;i++)
        {
            cout<<s[i]<<':';
            for(0;j<(i+1)*5;j++)
            {
                p[i]+=b[j];
                cout<<b[j];
            }
            j+=5;
                cout<<'    '<<"总点数为:"<<p[i]<<endl;
        }
    }
private:
    int* b;
    string* s;
};

void main()
{
    int a[13]={2,3,4,5,6,7,8,9,10,11,12,13,14};
    int b[13]={14,13,12,11,10,9,8,7,6,5,4,3,2};
    int c[13]={8,7,6,5,4,3,2,9,10,11,12,13,14};
    int d[13]={8,9,10,11,12,13,14,7,6,5,4,3,2};

    card s1;
    s1.put(a,b,c,d);
    bridge s2;
    s2.deal(s1);
    char s;
    do
    {
        cout<<"***洗牌***"<<endl;
        bridge s3(4);
        s3.deal(s1);
        cout<<"是否发牌,按y或n"<<endl;
        cin>>s;
        if(s=='y')
            s3.get1();
      
        cout<<"继续娱乐请按n"<<endl;
        cin>>s;
    }while(s=='n');
   
    int n;
    do
    {
        cout<<"输入参加人数"<<endl;
        cin>>n;
        cout<<"***洗牌***"<<endl;
        poker s4(n);
        s4.deal(s1,n);
        cout<<"是否发牌,按y或n"<<endl;
        cin>>s;
        if(s=='y')
            s4.get2(n);
        
        cout<<"继续娱乐请按n"<<endl;
        cin>>s;
    }while(s=='n');
}

2010-11-15 22:23
m21wo
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:4
帖 子:440
专家分:1905
注 册:2010-9-23
收藏
得分:0 
加随机!!

If You Want Something, Go Get It, Period.
2010-11-15 22:41
快速回复:发牌程序求高手支招 。。。。。谢谢。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021619 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved