求求大佬帮忙看一下有什么问题试了很多的数都正确,70分

P1307 [NOIP2011 普及组] 数字反转

ammmmmgoding @ 2023-10-26 18:34:32

#include <stdio.h>

int main() {
    int x;
    scanf("%d", &x); int ooo = x;
    if (x < 0) { x *= (-1); }
    int t = x; int count = 0; int f = x; if (x == 0)printf("0");
    else {
        for (int i = 0; i < 100000000; i++)
            while (x > 0) { x /= 10; count++; }
        for (int i = 0; i < count; i++) {
            if (ooo > 0) {
                if (t < 9) { printf("%d", t); }
                else { f = t % 10; t /= 10; if (f != 0) { printf("%d", f); } }
            }
            else {
                if (i == 0) { printf("%c",'-'); }
                f = t % 10; t /= 10; if (f != 0) {
                    printf("%d", f);
                }
            }
        }
    }
        return 0;
}

by Henry2012 @ 2023-10-26 18:48:39

转换之后前导零要忽略,但是你把中间的0也去掉了


by Henry2012 @ 2023-10-26 18:49:47

比如1002这个数据,你会输出21,但是结果是2001


|