如何初始化一副纸牌的 3D 数组
How to initialize 3D array for deck of cards
// deck of cards
#include <iostream>
#include <string>
using namespace std;
int main()
{
int i, j, k;
char arr[4][13][14] =
{
{
{ heart one, heart two, heart three, heart four, heart five, heart six, heart seven, heart eight, heart nine, heart ten, heart jack, heart queen, heart king, heart ace }
},
{
{ diamond one, diamond two, diamond three, diamond four, diamond five, diamond six, diamond seven, diamond eight, diamond nine, diamond ten, diamond jack, diamond queen, diamond king, diamond ace }
},
{
{ club one, club two, club three, club four, club five, club six, club seven, club eight, club nine, club ten, club jack, club queen, club king, club ace }
},
{
{ spade one,spade two, spade three, spade four, spade five, spade six, spade seven, spade,eight, spade nine, spade ten, spade jack, spade queen, spade king, spade ace }
},
};
clrscr();
printf(":::3D Array:::nn");
for(i=0; i<4;i++)
{
for(j=0;j<13;j++)
{
for(k=0;k<14;k++)
{
printf("%dt",arr[i][j][k]);
}
printf("n");
}
printf("n");
}
return 0;
}
我收到一个错误,其中没有指定心形、钻石、铁锹、球杆。 但是我设置了字符类型,有人可以给我一些关于如何解决这个问题的指示吗?我想要一副牌的 3D 数组,4 行(花色(,13 列(二,三,...,ace(和 14 个数据位置(最长的是钻石 8,例如,取 13 个元素(。请帮忙!
您可以自下而上地开始构建声明以帮助您更好地理解声明语法。
您将如何声明 14 char
s 的数组?
char card[14] = "heart two";
现在,您将如何创建其中 13 个的数组?
char suite[13][14] = {"heart two", "heart three", "heart four" ...};
现在,您将如何创建其中 4 个的数组?
char deck[4][13][14] =
{
{"heart two", "heart three", "heart four" ...},
{"diamond two", "diamond three", "diamond four" ...},
{"club two", "club three", "club four" ...},
{"spade two", "spade three", "spade four" ...}
};
我猜你想要这样的东西。此外,一副牌中没有 1。
const char *arr[4][13]=
{
{"heart two", "heart three",...},
{"diamond two", "diamond three",...},
{"club two", "club three",...},
{"spade two", "spade three",...}
};
相关文章:
- 如何计算 3d 数组中的索引值在内存中的位置?如何计算字符**中的索引值在内存中的位置?
- 我是 c++ 的新手,有没有一种算法可以找到 3d 数组中最接近的 0 的距离?
- 如何用零填充 3D 数组?
- 将长度可变的 C99 静态 3D 数组传递给函数
- C :将矢量重新为3D数组
- 将动态 3D 数组发送到 C++ 中的函数
- C++ 3D 数组到 1D 会导致堆缓冲区溢出
- 初始化const 3D数组成员变量
- 处理3D数组的边缘和角案例的方法
- 将2D数组的实例分配给3D数组中的索引
- 使用 vector 在 c++ 中声明 3D 数组结构
- 为什么C CHAR数据类型3D数组通过参数第一个括号为空白
- 可以使用 std::copy 将 3D 数组复制到矢量
- 我的重载 [] 运算符不适用于伪 3D 数组
- 从 3D 数组转换为 1D 数组失败
- 如何将3D .OBJ对象表示为3D数组
- 如何在C++中定义每个维度具有不同类型的 3D 数组
- CPP 3D 动态创建由单个内存块组成的 3D 数组
- 视觉读取列文本数据并在C++中放入 3D 数组
- 将 3D 数组的索引传递给函数