为什么我用的\r还是移到了下一行

P1320 压缩技术(续集版)

remiriya @ 2022-11-13 19:15:16

# include <stdio.h>
int main()
{
    unsigned N = 0, a, b, c, n;
    putchar('0');
    for (n = 1,b = 0,c = 0; 1;n++) {
        a = getchar();
        if (a == '0') {
            b++; if (c != 0) {
                printf(" %u", c); c = 0;
            }
        }
        if (a == '1') {
            c++; if (b != 0) {
                printf(" %u", b); b = 0;
            }
        }
        if (a == '\n') {
            n=n-2;
            if (N == 0) {
                N = n;
            }
        }
        if (n == N * N) {
            printf(" %u\r", c + b);
            printf("%u", N);
            break;
        }
    }
    return 0;
}

输入为样例 输出为 0 3 1 6 1 6 4 3 1 6 1 6 1 3 7

7


by ud2_ @ 2022-11-13 19:17:33

评测机不可能开个认识 \r 的控制台窗口跑你的代码。


|