为什么#2#3WA 求助大佬

P1307 [NOIP2011 普及组] 数字反转

朕爱学习 @ 2019-08-08 21:24:11

#include<bits/stdc++.h>
using namespace std;
int a,i,md;
string b;
char num[100000000];
int main()
{
    cin>>b;
    a=b.length();
    if(a==1&&b[0]=='0')
    {
        cout<<0;
        return 0;
    }
    if(b[0]=='-')
    {
        cout<<"-";
        for(i=1;i<a;i++)
        {
            num[i]=b[a-i];
        }
        for(i=1;i<a;i++)
        {
            if(num[i]=='0'&&i==1)
            cout<<"";
            if(num[i]=='0'&&i!=1)
            {
                cout<<num[i];
                continue;
            }
            if(num[i]!='0')
            {
                cout<<num[i];
                continue;
            }
        }
    }
    else if(b[0]!='-')
    {
        for(i=1;i<=a;i++)
        {
            num[i]=b[a-i];
        }
        for(i=1;i<=a;i++)
        {
            if(num[i]=='0'&&i==1)
            cout<<"";
            if(num[i]=='0'&&i!=1)
            {
                cout<<num[i];
                continue;
            }
            if(num[i]!='0')
            {
                cout<<num[i];
                continue;
            }
        }
    }
    return 0;
}

by 朕爱学习 @ 2019-08-08 21:43:00

#include<bits/stdc++.h>
using namespace std;
int a,i,md;
string b;
char num[100000000];
int main()
{
    cin>>b;
    a=b.length();
    if(a==1&&b[0]=='0')
    {
        cout<<0;
        return 0;
    }
    if(b[0]=='-')
    {
        cout<<"-";
        for(i=1;i<a;i++)
        {
            num[i]=b[a-i];
        }
        for(i=1;i<a;i++)
        {
            if(num[i]=='0'&&i==1)
            continue;
            if(num[i]=='0'&&num[i-1]=='0'&&i>1)
            continue;
            if(num[i]=='0'&&i!=1&&num[i+1]!=0)
            {
                cout<<num[i];
                continue;
            }
            if(num[i]!='0')
            {
                cout<<num[i];
                continue;
            }
        }
    }
    else if(b[0]!='-')
    {
        for(i=1;i<=a;i++)
        {
            num[i]=b[a-i];
        }
        for(i=1;i<=a;i++)
        {
            if(num[i]=='0'&&i==1)
            continue;
            if(num[i]=='0'&&num[i-1]=='0'&&i>1)
            continue;
            if(num[i]=='0'&&i!=1&&num[i+1]!=0)
            {
                cout<<num[i];
                continue;
            }
            if(num[i]!='0')
            {
                cout<<num[i];
                continue;
            }
        }
    }
    return 0;
}

by 朕爱学习 @ 2019-08-08 21:43:46

楼上是新的代码 #2#3对了 但是#9#10又错了


by wuhan717 @ 2019-08-18 20:38:54

太麻烦,看不懂 正确的是:

include <iostream>

using namespace std; int main () { int t=0,m,a; cin>>m; while(m!=0) { a=m%10; t=t*10+a; m=m/10; } cout<<t<<endl; }


|