自测答案都对,全RE

P1319 压缩技术

Griezmann_7 @ 2023-09-17 15:59:34

#include<iostream>
#include<cstdio>
using namespace std;
int ans[205][205] = {};//以二维数组存储答案
int ans1[40005] = {};//以一维数组存储答案
/*思路:将压缩码翻译并统计到一维数组中,
再将一维数组的数据转移到二维数组
最后输出二维数组
*/
int main() {
    int n;
    cin >> n;
    int x, lastone=0;
    bool flag = false;//先是0
    int sum=1;
    int num = 0;
    //false为0 true为1
    do {
        cin >> x;
        for (int i = lastone+1; i <= lastone+x; i++) {
            if (flag)num= 1;
            else num= 0;
            ans1[sum] =num;
            sum++;
        }
        lastone = x; flag = !flag;
    } while (getchar() != '\n');//输入未知个数的数据

    sum = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            ans[i][j] = ans1[sum];
            sum++;
            cout << ans[i][j];
        }
        cout << endl;
    }

}

|