求大佬看看呀,改了两遍都八十,但是WA点不一样

P1307 [NOIP2011 普及组] 数字反转

sygzzyr @ 2019-07-03 17:49:08

include<iostream>

include<cstring>

using namespace std; char c[1000000000]; int main() {

int i,l;
cin>>c;
l=strlen(c)-1;
if(c[0]=='-')
{
    cout<<"-";
    if(c[l]=='0')
    {
        for(i=(l-1);i>0;i--)
        {
            if((c[i]==c[i+1])&&(c[i+1]=='0')) continue;
            else cout<<c[i];

        }  
    }
    else{
        for(i=l;i>0;i--)
        cout<<c[i];
    }
} 
else
{
    if(c[l]=='0')
    {
        for(i=(l-1);i>=0;i--)
        {
            if((c[i]==c[i+1])&&(c[i+1]=='0')) continue;
            else cout<<c[i];

        }  
    }
    else{
        for(i=l;i>=0;i--)
        cout<<c[i];
    }
}
return 0;

}


by 赫敏·东方延绪 @ 2019-07-03 20:29:26

@sygzzyr https://www.luogu.org/recordnew/show/20265772


by sygzzyr @ 2019-07-04 09:41:19

蟹蟹大佬们,问题已经解决啦(鞠躬)


by JamesMessi @ 2019-08-21 11:47:25

#include<bits/stdc++.h>
using namespace std;
int a[1000];
int dao(int n){
    int s=0;
    while (n!=0){
        s=s*10+n%10;
        n=n/10;
    }
    return s;
}
int main(){
    int n;
    cin>>n;
    cout<<dao(n);
    return 0;
}

上一页 |