OJ解决Presentation Error

在练习UVa1225的时候,提交如下代码,最终结果为Presentation Error:

#include<stdio.h>
#include<string.h>
int main()
{
    int n;
    int T;
    scanf("%d", &T);
    while(T--){
    int a[10];
    memset(a, 0, sizeof(a));
    scanf("%d", &n);
    for(int i = 0; i <= n; i ++)
    {
        int j;
        j = i;
        while(j)
        {
            a[j%10] ++;
            j /= 10;
        }
    }
    for(int i = 0; i < 10; i++)
        printf("%d ", a[i]);
    printf("\n");
    }
    return 0;
}

平时上课总是做presentation,现在出了presentation error应该是结果显示的时候出了问题,于是修改代码如下:

#include<stdio.h>
#include<string.h>
int main()
{
    int n;
    int T;
    scanf("%d", &T);
    while(T--){
    int a[10];
    memset(a, 0, sizeof(a));
    scanf("%d", &n);
    for(int i = 0; i <= n; i ++)
    {
        int j;
        j = i;
        while(j)
        {
            a[j%10] ++;
            j /= 10;
        }
    }
    for(int i = 0; i < 9; i++)
        printf("%d ", a[i]);
    printf("%d\n", a[9]);
    }
    return 0;
}

提交后,成功AC了。

总结下,遇到Presentation Error是输出出现了问题,修改下输出结果,注意空格或者制表符。

About the Author

admin

Leave a Reply

Your email address will not be published. Required fields are marked *