P1307 [NOIP2011 普及组] 数字反转

· · 题解

栈

#include <bits/stdc++.h>
using namespace std;
char a[100001];
int t=0;
int main()
{
    string b,c;
    bool sign=false,flag=false;
    cin>>c;
    for(int i=0;i<=c.length();i++)
    {
        if(c[i]=='-') s=true;
        else a[++t]=c[i];
    }    
    if(s==true)    b+="-";
    t--;
    for(t;t>=0;t--)
    {
        if(a[t]!='0'&&f==false) f=true,b+=a[top];    
        else if(f==true) b+=a[t];
    }
    int i=atoi(b.c_str());
    cout<<i;
    return 0;    
}//用栈的呢应该都懂吧,不需要解释了吧