| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 780 人关注过本帖
标题:[推荐]发牌(能运行,但最后提示有错误内存不能为写)
只看楼主 加入收藏
killqq
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2005-5-3
收藏
 问题点数:0 回复次数:3 
[推荐]发牌(能运行,但最后提示有错误内存不能为写)
#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
void print(int);
const int s=51;
void main()
{
 int a[s+1];
 int i,j;
 for(i=0;i<=s;i++)
  a[i]=i;
 int hand [4][5];
 srand(time(0));
 int temp;
 for(i=s;i>=31;i--)
 {
  int r=rand()%(i+1);
  temp=a[r];
  a[r]=a[i+1];
  a[i+1]=temp;
 }
 int ss=s;
 for(i=0;i<=4;i++)
  for(j=0;j<=3;j++)
  {
   hand[j][i]=a[ss];
   ss--;
  }
  for(i=0;i<=3;i++)
  {
   cout<<"Player"<<(i+1)<<"'s hand:"<<endl;
   for(j=0;j<=4;j++)
   {
    print(hand[j][i]);
    cout<<" ";
    cout<<endl;
   }
  }
}
void print(int card_value)
{
 if(card_value%4==0)
  cout<<"黑桃";
 else if(card_value%4==1)
  cout<<"梅花";
 else if(card_value%4==2)
  cout<<"方片";
 else
  cout<<"红桃";
 if(card_value<=36)
  cout<<(card_value/4+2);
 else if(card_value<=39)
  cout<<"J";
 else if(card_value<=43)
  cout<<"Q";
 else if(card_value<=47)
  cout<<"K";
 else
  cout<<"A";
}
搜索更多相关主题的帖子: 内存 提示 发牌 运行 推荐 
2005-05-16 19:24
tary
Rank: 1
等 级:新手上路
帖 子:780
专家分:0
注 册:2004-10-5
收藏
得分:0 
老大, 你写程序能来点注释吗? 我都看晕了..
我运行了一下, 可以运行...
有可能是你的内存没分配好吧.. . 不太清楚 ..因为我看了好多遍, 程序还没完全搞懂...

┌→¨ ≮我可以学会对你很冷落≯¨←┐ │  <却学不╓══╦══╖会将爱> │ │¨←┐ ╭╩╮哭‖哭╭╩╮ ┌→¨│ └──┘收 ╲╱ ◇‖◇ ╲╱回└──┘
2005-05-17 08:44
killqq
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2005-5-3
收藏
得分:0 
不好意思
2005-05-30 22:44
killqq
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2005-5-3
收藏
得分:0 
//为4个玩家随机发5张牌。
#include&lt;iostream&gt;
#include&lt;ctime&gt;
#include&lt;cstdlib&gt;
using namespace std;
void print(int);
const int s=51;
void main()
{
 int a[s+1];
 int i,j;
 for(i=0;i&lt;=s;i++)
  a[i]=i;
 int hand [4][5];
 srand(time(0));
 int temp;
 //把发出去的牌放到数组的最后避免重复
 for(i=s;i&gt;=31;i--)
 {
  int r=rand()%(i+1);
  temp=a[r];
  a[r]=a[i+1];
  a[i+1]=temp;
 }
 //给玩家分牌
 int ss=s;
 for(i=0;i&lt;=4;i++)
  for(j=0;j&lt;=3;j++)
  {
   hand[j][i]=a[ss];
   ss--;
  }
  //输出每个玩家
  for(i=0;i&lt;=3;i++)
  {
   cout&lt;&lt;"Player"&lt;&lt;(i+1)&lt;&lt;"'s hand:"&lt;&lt;endl;
   for(j=0;j&lt;=4;j++)
   {
    print(hand[j][i]);
    cout&lt;&lt;" ";
    cout&lt;&lt;endl;
   }
  }
}
//输出牌
void print(int card_value)
{
 if(card_value%4==0)
  cout&lt;&lt;"黑桃";
 else if(card_value%4==1)
  cout&lt;&lt;"梅花";
 else if(card_value%4==2)
  cout&lt;&lt;"方片";
 else
  cout&lt;&lt;"红桃";
 if(card_value&lt;=36)
  cout&lt;&lt;(card_value/4+2);
 else if(card_value&lt;=39)
  cout&lt;&lt;"J";
 else if(card_value&lt;=43)
  cout&lt;&lt;"Q";
 else if(card_value&lt;=47)
  cout&lt;&lt;"K";
 else
  cout&lt;&lt;"A";
}
2005-05-30 22:58
快速回复:[推荐]发牌(能运行,但最后提示有错误内存不能为写)
数据加载中...
 
   



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

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