版本比较
题解 P2615 【神奇的幻方】
正文
增加 6 行删除 6 行
14 行未改动1516171819192021222324252526272829293031313233333435353637383910 行未改动14 行未改动+ 经过以上优化,每个 `if` 块只有一条语句,省略掉了大括号
```cpp//【P2615】神奇的幻方 - 洛谷 - 100#include <iostream> #include <iostream>
int a[40][40] = { 0 };
int main() { int n; std::cin >> n; std::cin >> n; int step = 1; // 填到几了 int posx, posy; // 上一个点坐标 while (step <= n * n) { if (step == 1) if (step == 1) a[posx = 1][posy = n / 2 + 1] = step++; else if (posx == 1 && posy != n) else if (posx == 1 && posy != n) a[posx = n][++posy] = step++; else if (posx != 1 && posy == n) else if (posx != 1 && posy == n) a[--posx][posy = 1] = step++; else if (posx == 1 && posy == n) else if (posx == 1 && posy == n) a[++posx][posy] = step++; else if (posx != 1 && posy != n) if (a[posx - 1][posy + 1] == 0) a[--posx][++posy] = step++;10 行未改动