为啥最后一个过不了,代0进去也可以输出0呀┭┮﹏┭┮

P1307 [NOIP2011 普及组] 数字反转

xiaoqi4487 @ 2024-10-28 12:58:26

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
using namespace std;
int main()
{
    int num[11] = { 0 };
    char ch;
    int i = 1;
    int len = 0;
    int t=0;
    while ((ch = getchar()) != '\n')
    {
        if (ch != '-')
        {
            len++;
            num[i] = ch - '0';
            i++;
        }
        else
            t++;
    }
    int n = 0;
    for (i = 1; i <= len; i++)
        n = n + num[i] * pow(10, i-1);
    if(t==0)
    cout << n;
    else
    cout << -n;

}

|