995

P1307 [NOIP2011 普及组] 数字反转

LYH_yes @ 2024-12-09 17:07:34

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b;
    int s=0,m=0;
    cin>>a;
    if(a[0]=='-')
    {
        cout<<"-";
    }
    for(int i=a.size()-1;i>0;i--)
    {
        s++;
        b[s]=a[i];

    }
    for(int i=1;i<=b.size();i++)
    {
        if(b[i]==0 && m==0)
        {
            continue;
        }
        if(b[i]!=0)
        {
            m++;
            cout<<b[i];
        }
    }
    return 0;
}

by KarmaticEnding @ 2024-12-09 17:41:33

b[i]==0 改成 b[i]=='0'

b[i]!=0 改成 b[i]!='0'

@LYH_yes


|