lht20090314 @ 2023-07-02 16:29:01
代码:
#include <iostream>
using namespace std;
int main()
{
int picture[202][202] = {0}, num[100], n, x = 1, y = 1, cnt = 0, cnt2 = 1; // picture是点阵图,n是点阵图大小,x、y是数组的坐标
bool state = false; // true为1,false为0
cin >> n;
for (int i = 1; ; i++)
{
cin >> num[i];
if (cin.get() == '\n') break;
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
picture[i][j] = state ? 1 : 0;
cnt++;
if (cnt == num[cnt2]) cnt = 0, state = !state, cnt2++;
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
cout << picture[i][j];
cout << endl;
}
return 0;
}
各位大佬请问应该怎么优化?
by Weizhuo_Zhao @ 2023-07-02 17:02:02
一般情况:死循环 三般情况:太慢要优化