只有最后一个AC,其余都是WA,本地没毛病,但是过不了,求大神

P1015 [NOIP1999 普及组] 回文数

Leeorange @ 2022-03-06 10:41:30

#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
long long int N, Ma,Mb;
char M1[101];

int main()
{
    cin >> N ;
    cin.ignore();
    cin.getline(M1, 101);

    int step = 0;
    bool isHui = 0;

    for (; !isHui;step++)

    {

        int sizeM = 0;
        for (; M1[sizeM] != '\0'; sizeM++)
        {
        }

        if (step > 30)
        {
            isHui = 0;
            cout << "Impossible!";
            return 0;
        }

        //将N进制的数字转化为十进制以便进行加法
        //Ma就是这个
        Ma = 0;
        for (int i = 0; i <= sizeM; i++)
        {
            if (M1[i] >= '0' && M1[i] <= '9')
            {
                Ma += int(M1[i] - '0') * pow(N, sizeM - i-1);
            }
            if (M1[i] >= 'A' && M1[i] <= 'Z')
            {

                Ma += int(M1[i] - 'A'+10) * pow(N, sizeM - i-1);
            }
            if (M1[i] >= 'a' && M1[i] <= 'z')
            {
                Ma += int(M1[i] - 'a'+10) * pow(N, sizeM - i-1);
            }

        }

        //Mb是这个
        Mb = 0;
        for (int i = 0; i <= sizeM; i++)
        {
            if (M1[i] >= '0' && M1[i] <'A')
            {
                Mb += int(M1[i] - '0') * pow(N, i);
            }
            if (M1[i] >= 'A' && M1[i] <= 'Z')
            {

                Mb += int(M1[i] - 'A'+10) * pow(N, i);
            }
            if (M1[i] >= 'a' && M1[i] <= 'z')
            {
                Mb += int(M1[i] - 'a'+10) * pow(N, i);
            }

        }

        Ma = Ma + Mb;
    //将Ma转化为N进制的M1
        int i = 0;
        for (;Ma!=0 ; i++,Ma/=N)
        {

            char a = char((Ma % N)+'0');

            M1[i] = a;
        }
        M1[i+1]= '\0';
        //判断是否回文
        for (int j = 0; j < i; j++)
        {
            if (M1[j] != M1[i - j - 1])
            {
                isHui = 0;
                break;
            }
            if ((j == i - 1)&&(M1[j]==M1[i-j-1]))
            {
                cout <<"STEP="<< step+1;
                return 0;

            }
        }
    }
    cout << "Impossible!";
    return 0;
}

本地没有毛病,但是为啥在线ide就不可以!!!!!!求指点!


|