38(2023.11.29).........

38(2023.11.29)........._第1张图片

#include
using namespace std;
int main()

{
    int n;
    cin >> n;
    int arr[201][201] = {};
    int x = 0;
    int y = 0;
    int times=0;
    int sum = 0;
    arr[n - 1][n - 1] = 2;
    int start = 1;
    while (sum!=n*n)
    {

        if (times == 0)
        {
            cin >> times;
            sum+=times;
            if (start == 0)start = 1;
            else if (start == 1)start = 0;
        }
        for (int i = 0;i < times;i++)
        {
            if (y == n)
            {
                x++;
                y = 0;
            }
            arr[x][y] = start;
            y++;

        }
        times = 0;
    }
    for (int i = 0;i < n;i++)
    {
        for (int j = 0;j < n;j++)
        {
            cout << arr[i][j];
        }
        cout << endl;
    }

    system("pause");
    return 0;
}

38(2023.11.29)........._第2张图片 

 

你可能感兴趣的:(算法,数据结构)