求帮看看哪里错了

P1307 [NOIP2011 普及组] 数字反转

absconded @ 2021-11-20 21:35:12

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
    int n = 11;
    char a[11];
    int b[10];

    int cnt = 0;
    memset(b, -1, sizeof b);
    if(a[0] == '-')
    {
        for (int i = 1; i <= n; i ++ )
        {
            b[i] = a[i] - '0';
            while(b[i]!=-1)
            cnt ++ ;
            if ( b[cnt--] == 0)
            {
                printf("-");
                for (int i = cnt - 1; i >= 1; i -- )
                cout << b[i];
            }
            else 
            {
                printf("-");
                for (int i = cnt ; i >= 1; i -- )
                cout << b[i];
            }
        }

    }
    else
    {
        if ( b[cnt--] == 0)
            {
                for (int i = cnt - 1; i >= 0; i -- )
                cout << b[i];
            }
        else 
            {
                for (int i = cnt ; i >= 0; i -- )
                cout << b[i];
            }
    }
    return 0;     
}

by wenlebo @ 2022-02-15 10:57:35

你没输入


|