样例 第一个数据都是正确的 也试了其他数据 还是0分 C语言

P1320 压缩技术(续集版)

hhh21g @ 2023-10-31 21:57:13

#include <stdio.h>
int main()
{
    char num[201][201] = { 0 };
    int i=0, j=0, k=0;
    int n = 202;
    int shu[40000]={0};
    for (i = 0; i < n; i++) {
        for (j = 0; j <= n; j++) {
            scanf("%c", &num[i][j]);
            if (num[i][j] == '\n'||num[i][j]==' ')
            {
                n = j ;
                break;
            }
        }
    }
    if (num[0][0] == '1') {
        shu[k] = 0;
        k++;
    }
    i = 0; j = 0;
    for (; i < n; i++) {
        for (; j < n; j++) {
            if (j + 1 < n) {
                if (num[i][j] == num[i][j + 1]) {
                    shu[k]++;
                }
                if (num[i][j] != num[i][j + 1]) {
                    k++;
                }
            }
            else if (j + 1 == n) {
                if (num[i][j] == num[i + 1][0]) {
                    shu[k]++;
                    j = 0;
                    break;
                }
                else {
                    k++;
                    j = 0;  
                    break;
                }
            }
        }
    }
    printf("%d ", n);
    i = 0;
    for (i = 0; i < k; i++) {
        if (i == 0 && shu[i] == 0) printf("%d ", shu[i]);
        else printf("%d ", shu[i]+1);
    }
    return 0;
}

by hhh21g @ 2023-10-31 22:12:13

#include <stdio.h>
int main()
{
    char num[201][201] = { 0 };
    int i = 0, j = 0, k = 0;
    int n = 202;
    int shu[40000] = { 0 };
    for (i = 0; i < n; i++) {
        for (j = 0; j <= n; j++) {
            scanf_s("%c", &num[i][j]);
            if (num[i][j] != '1' && num[i][j] != '0')//修改的第一处
            {
                n = j;
                break;
            }
        }
    }
    if (num[0][0] == '1') {
        shu[k] = 0;
        k++;
    }
    i = 0; j = 0;
    for (; i < n; i++) {
        for (; j < n; j++) {
            if (j + 1 < n) {
                if (num[i][j] == num[i][j + 1]) {
                    shu[k]++;
                }
                if (num[i][j] != num[i][j + 1]) {
                    k++;
                }
            }
            else if (j + 1 == n) {
                if (num[i][j] == num[i + 1][0]) {
                    shu[k]++;
                    j = 0;
                    break;
                }
                else {
                    k++;
                    j = 0;
                    break;
                }
            }
        }
    }
    printf("%d ", n);
    i = 0;
    for (i = 0; i < k; i++) {
        if (i == 0 && shu[i] == 0&&num[i][i]==1) printf("%d ", shu[i]);//修改的第二处
        else printf("%d ", shu[i] + 1);
    }
    return 0;
}

改了这两处之后还是全wa 真的找不出错误了 求助大佬


|