求救

P1307 [NOIP2011 普及组] 数字反转

SpecialSpec @ 2016-11-10 19:00:30

为啥只有70分。

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int n,i;
    cin>>n;
    int a[1001]={0};
    int lengh=0;
    if(n==0)
    {
        cout<<0<<endl;
        return 0;
    }
    if(n<0)
    {
        cout<<"-";
        n=-n;
    }
    while(n!=0)
    {
        a[++lengh]=n%10;
        n=n/10;
    }
    for(i=1;i<=lengh;i++)
    {
        if(a[i]!=0) cout<<a[i];
    }
    return 0;
}

by NuclearBase_ACE @ 2016-11-12 18:21:58

送你一个:

#include<iostream>
#include<string> 
using namespace std;
int main()
{
    bool s = 1,c = 0;
    string a;
    cin>>a;
    if(a[0] == '-')
    {
        cout<<'-';
        c = 1;
    }
    for(int i = a.length()-1;i >= 0;i--)
    {
        if(a[i] == '0' && s)
        {} 
        else 
        {
            s == 0;
            if( c && i == 0)
            {}
            else 
                cout<<a[i];    
        } 
    }
    return 0;
}

by NuclearBase_ACE @ 2016-11-12 18:29:40

那个错了,这个对的:

#include<iostream>
#include<string> 
using namespace std;
int main()
{
    bool s = 1,c = 0;
    string a;
    cin>>a;
    if(a[0] == '-')
    {
        cout<<'-';
        c = 1;
    }
    for(int i = a.length()-1;i >= 0;i--)
    {
        if(a[i] == '0' && s)
        {} 
        else 
        {
            s = 0;
            if( c && i == 0)
            {}
            else 
                cout<<a[i];    
        } 
    }
    return 0;
}

by 讚臣 @ 2016-11-30 11:55:17

用pascal怎么做,我的全错,求大神帮忙

var a,b,c,d,i:longint;
    as:array[0..1000] of longint;
begin
  read(a);
  c:=a;
  b:=0;
  while a<>0 do
  begin
    a:=a div 10;
    inc(b);
  end;
  while c<>0 do
  begin
    for i:=1 to b do
    as[b]:=c mod 10;
    c:=c div 10;
  end;
  for i:=b downto 1 do
  write(as[b]);
end.

|