lht20090314 @ 2022-11-12 21:57:57
照着书本的代码写的,检查了好多遍,但是没有发现问题,请大佬们帮忙看看到底哪里有问题?
代码:
#include <iostream>
using namespace std;
int main()
{
int tubes[10][8] = { // 数码 i 的第 j个显示管,tubes[i][0] 表示数码 i 要显示几根显示管,tubes[i][j] 表示数码 i 的第 j 个显示管是什么
{6, 0, 1, 2, 4, 5, 6}, {2, 2, 5}, {5, 0, 2, 3, 4, 6}, {5, 0, 2, 3, 5, 6}, // 0123
{4, 1, 2, 3, 5}, {5, 0, 1, 3, 5, 6}, {6, 0, 1, 3, 4, 5, 6}, {3, 0, 2, 5}, // 4567
{7, 0, 1, 2, 3, 4, 5, 6}, {6, 0, 1, 2, 3, 5, 6} // 89
};
int dot[7][3][2] = { // 每个显示管的 3 个点相对于左上角的坐标偏移
{{0, 0}, {0, 1}, {0, 2}},
{{0, 0}, {1, 0}, {2, 0}},
{{0, 2}, {1, 2}, {2, 2}},
{{2, 0}, {2, 1}, {2, 2}},
{{2, 0}, {3, 0}, {4, 0}},
{{2, 2}, {3, 2}, {4, 2}},
{{4, 0}, {4, 1}, {4, 2}}
};
char num[110], out[5][500];
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> num[i];
// 初始化输出列表
for (int i = 0; i < 5; i++) // 行
for (int j = 0; j < 4 * n - 1; j++) // 列
out[i][j] = '.';
for (int i = 0; i < n; i++)
{
int basex = 0, basey = i * 4, digit = num[i] - '0'; // basex 和 basey 是每个数字左上角的坐标值, digit 是正在处理哪一个数码(转换成 int)
for (int j = 1; j <= tubes[digit][0]; j++) // 处理每个要被点亮的显示管
{
int tubenum = tubes[digit][j]; // 第几个显示管点亮
out[basex + dot[tubenum][0][0]][basey + dot[tubenum][0][1]] = 'X';
out[basex + dot[tubenum][1][0]][basey + dot[tubenum][1][1]] = 'X';
out[basex + dot[tubenum][2][0]][basey + dot[tubenum][2][1]] = 'X';
}
}
for (int i = 0; i < 5; i++, cout << endl)
for (int j = 0; i < 4 * n - 1; j++)
cout << out[i][j];
return 0;
}
by Jerrlee✅ @ 2022-11-12 22:05:25
for (int j = 0; i < 4 * n - 1; j++)
->for (int j = 0; j < 4 * n - 1; j++)
可 AC
by Jerrlee✅ @ 2022-11-12 22:05:30
@lht20090314
by lht20090314 @ 2022-11-12 22:23:39
@Jerrlee✅ 啊,打太快打错了,谢谢啦