P1307 数字反转

P1307 数字反转

#include 

using namespace std;

char n[11];
int x,type=1,m=0,a[11];
int main()
{
    cin>>n;
    for (int i=0;i<=10;i++)
    {
        if (n[i]=='\0')
        {
            x=i-1;
            break;
        }
    }
    for (int i=0;i<=x;i++)
    {
        if (n[i]=='-')
        {
            a[i]=int(n[i]);
            continue;
        }
        a[i]=n[i]-'0';
    }
    for (int i=0;i<=x;i++)
    {
        if (a[i]=='-')
        {
            type=2;
            break;
        }
    }
    if (type==1)
    {
        for (int i=x;i>=0;i--)
        {
            m=m*10+a[i];
        }
        cout <else
    {
        cout <<"-";
        for (int i=x;i>=1;i--)
        {
            m=m*10+a[i];
        }
        cout <return 0;
}

你可能感兴趣的:(luogu)