📄 programming.txt
字号:
switch (choice)
{
case 0: Shape0(hCol);
break;
case 1: Shape1(hCol);
break;
case 2: Shape2(hCol);
break;
case 3: Shape3(hCol);
break;
case 4: Shape4(hCol);
break;
case 5: Shape5(hCol);
break;
case 6: Shape6(hCol);
break;
case 8: Shape8(hCol);
break;
case 10: Shape10(hCol);
break;
case 12: Shape12(hCol);
break;
case 13: Shape13(hCol);
break;
case 14: Shape14(hCol);
break;
case 16: Shape16(hCol);
break;
case 17: Shape17(hCol);
break;
case 18: Shape18(hCol);
break;
default: break;
}
}
void Diamond::Shape0(int hCol)
{
// ****
// 0000
// 0000
map[MaxRow-1][hCol] = '*';
map[MaxRow-1][hCol+1] = '*';
map[MaxRow-1][hCol+2] = '*';
map[MaxRow-1][hCol+3] = '*'; // PrintMap(); getchar();
int h = GetHeight(MaxRow-2, hCol);
for (int i=0; i<4; i++)
MovePart(MaxRow-2, hCol+i, h);
}
void Diamond::Shape1(int hCol)
{
// *000
// *000
// *000
// *000
map[MaxRow-1][hCol] = '*';
map[MaxRow-2][hCol] = '*';
map[MaxRow-3][hCol] = '*';
map[MaxRow-4][hCol] = '*';
int h = GetHeight(MaxRow-5, hCol); // cout << h <<endl;PrintMap(); getchar();
MovePart(MaxRow-5, hCol, h);
}
void Diamond::Shape2(int hCol)
{
// 0*00
// ***0
// 0000
map[MaxRow-1][hCol+1] = '*';
map[MaxRow-2][hCol] = '*';
map[MaxRow-2][hCol+1] = '*';
map[MaxRow-2][hCol+2] = '*';
int h = GetHeight(MaxRow-3, hCol); //cout << h <<endl;PrintMap(); getchar();
for (int i=0; i<3; i++)
MovePart(MaxRow-3, hCol+i, h);
}
void Diamond::Shape3(int hCol)
{
// 0*00
// **00
// 0*00
map[MaxRow-1][hCol] = '*';
map[MaxRow-2][hCol-1] = '*';
map[MaxRow-2][hCol] = '*';
map[MaxRow-3][hCol] = '*';
int h = GetHeight(MaxRow-4, hCol); // cout << h <<endl;PrintMap(); getchar();
MovePart(MaxRow-3, hCol-1, h);
MovePart(MaxRow-4, hCol, h);
}
void Diamond::Shape4(int hCol)
{
// ***0
// 0*00
// 0000
map[MaxRow-1][hCol-1] = '*';
map[MaxRow-1][hCol] = '*';
map[MaxRow-1][hCol+1] = '*';
map[MaxRow-2][hCol] = '*';
int h = GetHeight(MaxRow-3, hCol); // cout << h <<endl;PrintMap(); getchar();
MovePart(MaxRow-2, hCol-1, h);
MovePart(MaxRow-3, hCol, h);
MovePart(MaxRow-2, hCol+1, h);
}
void Diamond::Shape5(int hCol)
{
// *000
// **00
// *000
map[MaxRow-1][hCol] = '*';
map[MaxRow-2][hCol] = '*';
map[MaxRow-2][hCol+1] = '*';
map[MaxRow-3][hCol] = '*';
int h = GetHeight(MaxRow-4, hCol); // cout << h <<endl;PrintMap(); getchar();
MovePart(MaxRow-4, hCol, h);
MovePart(MaxRow-3, hCol+1, h);
}
void Diamond::Shape6(int hCol)
{
// 0**0
// **00
// 0000
map[MaxRow-1][hCol+1] = '*';
map[MaxRow-1][hCol+2] = '*';
map[MaxRow-2][hCol] = '*';
map[MaxRow-2][hCol+1] = '*';
int h = GetHeight(MaxRow-3, hCol); // cout << h <<endl;PrintMap(); getchar();
MovePart(MaxRow-3, hCol, h);
MovePart(MaxRow-3, hCol+1, h);
MovePart(MaxRow-2, hCol+2, h);
}
void Diamond::Shape8(int hCol)
{
// **00
// 0**0
// 0000
map[MaxRow-1][hCol-1] = '*';
map[MaxRow-1][hCol] = '*';
map[MaxRow-2][hCol] = '*';
map[MaxRow-2][hCol+1] = '*';
int h = GetHeight(MaxRow-3, hCol); // cout << h <<endl;PrintMap(); getchar();
MovePart(MaxRow-2, hCol-1, h);
MovePart(MaxRow-3, hCol, h);
MovePart(MaxRow-3, hCol+1, h);
}
void Diamond::Shape10(int hCol)
{
// **00
// **00
// 0000
map[MaxRow-1][hCol] = '*';
map[MaxRow-1][hCol+1] = '*';
map[MaxRow-2][hCol] = '*';
map[MaxRow-2][hCol+1] = '*';
int h = GetHeight(MaxRow-3, hCol); // cout << h <<endl;PrintMap(); getchar();
MovePart(MaxRow-3, hCol, h);
MovePart(MaxRow-3, hCol+1, h);
}
void Diamond::Shape12(int hCol)
{
// 00*0
// ***0
// 0000
map[MaxRow-1][hCol+2] = '*';
map[MaxRow-2][hCol] = '*';
map[MaxRow-2][hCol+1] = '*';
map[MaxRow-2][hCol+2] = '*';
int h = GetHeight(MaxRow-3, hCol); // cout << h <<endl;PrintMap(); getchar();
for (int i=0; i<3; i++)
MovePart(MaxRow-3, hCol+i, h);
}
void Diamond::Shape13(int hCol)
{
// **00
// 0*00
// 0*00
map[MaxRow-1][hCol-1] = '*';
map[MaxRow-1][hCol] = '*';
map[MaxRow-2][hCol] = '*';
map[MaxRow-3][hCol] = '*';
int h = GetHeight(MaxRow-4, hCol); // cout << h <<endl;PrintMap(); getchar();
MovePart(MaxRow-2, hCol-1, h);
MovePart(MaxRow-4, hCol, h);
}
void Diamond::Shape14(int hCol)
{
// ***0
// *000
// 0000
map[MaxRow-1][hCol] = '*';
map[MaxRow-2][hCol] = '*';
map[MaxRow-1][hCol+1] = '*';
map[MaxRow-1][hCol+2] = '*';
int h = GetHeight(MaxRow-3, hCol); // cout << h <<endl;PrintMap(); getchar();
MovePart(MaxRow-3, hCol, h);
MovePart(MaxRow-2, hCol+1, h);
MovePart(MaxRow-2, hCol+2, h);
}
void Diamond::Shape16(int hCol)
{
// ***0
// 00*0
// 0000
map[MaxRow-1][hCol-2] = '*';
map[MaxRow-1][hCol-1] = '*';
map[MaxRow-1][hCol] = '*';
map[MaxRow-2][hCol] = '*';
int h = GetHeight(MaxRow-3, hCol); // cout << h <<endl;PrintMap(); getchar();
MovePart(MaxRow-2, hCol-2, h);
MovePart(MaxRow-2, hCol-1, h);
MovePart(MaxRow-3, hCol, h);
}
void Diamond::Shape17(int hCol)
{
// **00
// *000
// *000
map[MaxRow-1][hCol] = '*';
map[MaxRow-1][hCol+1] = '*';
map[MaxRow-2][hCol] = '*';
map[MaxRow-3][hCol] = '*';
int h = GetHeight(MaxRow-4, hCol);// cout << h <<endl;PrintMap(); getchar();
MovePart(MaxRow-4, hCol, h);
MovePart(MaxRow-2, hCol+1, h);
}
void Diamond::Shape18(int hCol)
{
// *000
// ***0
// 0000
map[MaxRow-1][hCol] = '*';
map[MaxRow-2][hCol] = '*';
map[MaxRow-2][hCol+1] = '*';
map[MaxRow-2][hCol+2] = '*';
int h = GetHeight(MaxRow-3, hCol); //cout << h <<endl;PrintMap(); getchar();
for (int i=0; i<3; i++)
MovePart(MaxRow-3, hCol+i, h);
}
///////////////////////////////////////////////////////////////////////
int Calc(const char map[][MaxCol], int outCmd[][2]);
void PrintMap(const char map[][MaxCol]);
void PrintOutCmd(const int outCmd[][2], int n);
int main()
{
char map[MaxRow][MaxCol] = {
'*','*','*','0','*','*','*','*','*',
'0','*','0','0','*','*','*','*','*',
'0','*','0','0','0','*','0','*','*',
'*','0','0','0','*','0','*','0','0',
'*','*','0','*','0','*','0','*','*',
'*','0','*','0','*','*','*','*','*',
'*','*','0','*','0','*','0','*','*',
'0','0','0','0','0','0','0','0','0',
'*','*','0','*','0','*','0','*','*',
'*','0','0','0','0','0','0','0','0',
'0','0','0','0','0','0','0','0','0',
'0','0','0','0','0','0','0','0','0',
'0','0','0','0','0','0','0','0','0',
'0','0','0','0','0','0','0','0','0',
'0','0','0','0','0','0','0','0','0',
'0','0','0','0','0','0','0','0','0',
'0','0','0','0','0','0','0','0','0',
'0','0','0','0','0','0','0','0','0',
'0','0','0','0','0','0','0','0','0',
'0','0','0','0','0','0','0','0','0'};
int outCmd[1000][2] = {0};
PrintMap(map); getchar();
int n = Calc(map, outCmd);
cout << "\nn = " << n << endl;
if (n > 0)
PrintOutCmd(outCmd, n);
getchar();
return 0;
}
int Calc(const char map[][MaxCol], int outCmd[][2])
{
Diamond my1(map); //创建对象
int out1[1000][2] = {0};
int count = 0; //累积添加模块数
int min = 0;
while (0 != my1.Check())
{
int highestCol = my1.GetHighestCol(); //读取具有最大高度的列号
int choice = my1.Choose1(highestCol); //选择所需的模块
my1.GetShape(choice, highestCol); //操作所选的模块
out1[count][0] = choice;
out1[count][1] = highestCol;
count++;
if (count > 999)
{
count = -1;
break;
}
}
min = count;
count = 0;
Diamond my2(map); //创建对象
int out2[1000][2] = {0};
while (0 != my2.Check())
{
int highestCol = my2.GetHighestCol(); //读取具有最大高度的列号
int choice = my2.Choose2(highestCol); //选择所需的模块
my2.GetShape(choice, highestCol); //操作所选的模块
out2[count][0] = choice;
out2[count][1] = highestCol;
count++;
if (count > 999)
{
count = -1;
break;
}
}
if (min == -1)
{
for (int i=0; i<count; i++)
{
outCmd[i][0] = out2[i][0];
outCmd[i][1] = out2[i][1];
}
return count;
}
else if ((count != -1 && min < count)|| count == -1)
{
for (int i=0; i<min; i++)
{
outCmd[i][0] = out1[i][0];
outCmd[i][1] = out1[i][1];
}
return min;
}
else
{
for (int i=0; i<count; i++)
{
outCmd[i][0] = out2[i][0];
outCmd[i][1] = out2[i][1];
}
return count;
}
}
void PrintMap(const char map[][MaxCol])
{
for (int i=MaxRow-1; i>=0; i--)
{
for (int j=0; j<MaxCol; j++)
cout << map[i][j];
cout << "\n";
}
}
void PrintOutCmd(const int outCmd[][2], int n)
{
for (int i=0; i<n; i++)
cout << outCmd[i][0] << " - " << outCmd[i][1] << "\t";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -