void 旋转菱形()
{//缘由https://ask.csdn.net/questions/1005557
int 数 = 0, 环 = 0, 行 = 0; cin >> 数;
int 量 = 数 * 2 - 1;
string* 符 = new string[量];
while (环++ < 数 * 4 - 2)符[行] += " ";
while (++行 < 量)符[行] = 符[行 - 1]; 行 = 环 = 0;
int 位 = 数 * 2 - 2, 判 = 1, 断 = 1, 转 = 0, x = 0;
while (++环 <= 数 * 数)
{
符[行].replace(位, 2, (环<10 ? "0" : "") + to_string(环));
//system("cls"); x = 0; while (x < 数 * 2)cout << 符[x++] << "\n";
位 += (判 ? 2 : -2), 行 += (断 ? 1 : -1);
if (行 < 转)
断 = 1, 行 += 2, ++转;
if (判 && 行 + 1 > 数)
判 = 0, 位 -= 4;
else if (!判 && 行 < 数)
判 = 1;
if (断 && (行 + 转) >= 量)
断 = 0, 行 -= 2, ++转;
else if (!断 && !行)
断 = 1, 行 += 转;
}
行 = 0; while (行 < 数 * 2)cout << 符[行++] << "\n";
}
void 旋转菱形()
{//缘由https://ask.csdn.net/questions/1005557
int 数 = 0, 环 = 0, 行 = 0; cin >> 数;
int 量 = 数 * 2 - 1;
string* 符 = new string[量];
while (环++ < 数 * 4 - 2)符[行] += " ";
while (++行 < 量)符[行] = 符[行 - 1]; 行 = 环 = 0;
int 位 = 数 * 2 - 2, 判 = 1, 断 = 1, 转 = 0, x = 0;
while (++环 <= 数 * 数)
{
符[行].replace(位, 3, (环<10 ? "00" : 环<100 ? "0" : "") + to_string(环));
//system("cls"); x = 0; while (x < 数 * 2)cout << 符[x++] << "\n";
位 += (判 ? 2 : -2), 行 += (断 ? 1 : -1);
if (行 < 转)
断 = 1, 行 += 2, ++转;
if (判 && 行 + 1 > 数)
判 = 0, 位 -= 4;
else if (!判 && 行 < 数)
判 = 1;
if (断 && (行 + 转) >= 量)
断 = 0, 行 -= 2, ++转;
else if (!断 && !行)
断 = 1, 行 += 转;
}
行 = 0; while (行 < 数 * 2)cout << 符[行++] << "\n";
}
控制台最多也就可看到20的旋转菱形.
void 旋转菱形(int a)
{//缘由https://ask.csdn.net/questions/1005557
int 数 = a, 环 = 0, 行 = 0; //cin >> 数;
int 量 = 数 * 2 - 1;
string* 符 = new string[量];
while (环++ < 数 * 4 - 2)符[行] += " ";
while (++行 < 量)符[行] = 符[行 - 1]; 行 = 环 = 0;
int 位 = 数 * 2 - 2, 判 = 1, 断 = 1, 转 = 0, x = 0;
while (++环 <= 数 * 数)
{
符[行].replace(位, 3, (环<10 ? "00" : 环<100 ? "0" : "") + to_string(环));
Sleep(40); system("cls"); x = 0; while (x < 数 * 2)cout << 符[x++] << "\n";
位 += (判 ? 2 : -2), 行 += (断 ? 1 : -1);
if (行 < 转)
断 = 1, 行 += 2, ++转;
if (判 && 行 + 1 > 数)
判 = 0, 位 -= 4;
else if (!判 && 行 < 数)
判 = 1;
if (断 && (行 + 转) >= 量)
断 = 0, 行 -= 2, ++转;
else if (!断 && !行)
断 = 1, 行 += 转;
}
//行 = 0; while (行 < 数 * 2)cout << 符[行++] << "\n";
}