只能得50分,求大神

P1307 [NOIP2011 普及组] 数字反转

xstxjx11 @ 2016-11-02 17:22:55

#include<stdio.h>
int main()
{
   long l=0,n=0,a[11],i=0,j=0;
   scanf("%d",&n);
  if(n<0) 
   {
   l=-n;
   printf("-");
   }
  else l=n;
   while(l>0)
   {
       a[i]=l%10;
       l=l/10;
       i++;
   }
   for(l=0;l<i;l++)
   {
       if(a[l]!=0||j==1)
       {
           printf("%d",a[l]);
           j=1;
       }
   }
   return 0;
}

by hly_hly @ 2016-11-02 19:27:19

#include<iostream>
#include<cmath>
int n,ans,k;
using namespace std;
int main()
{
    cin>>n;
    if(n<0)cout<<"-";
    n=abs(n);
    while(n>0){
        k=n%10;
        n/=10;
        ans=ans*10+k;
    }
    cout<<ans;
    return 0;
}

by xieyuntian @ 2016-11-11 20:12:44

#include<bits/stdc++.h>
using namespace std;
int main()
{
    char a[10001];
    int i=1;
    scanf("%s",&a);
    if(a[0]=='-')
    {
        bool pd=0;
        printf("-");
        for(int i=strlen(a)-1;i>=1;i--)
        {
            if(a[i]=='0'&&i==strlen(a)-1||a[i]=='0'&&pd==1)
            {
                pd=1;
                continue;
            }
            else
            {
                printf("%c",a[i]);
                pd=0;
            }
        }    
    }
    else
    {
        bool pd=0;
        for(int i=strlen(a)-1;i>=0;i--)
        {
            if(a[i]=='0'&&i==strlen(a)-1||a[i]=='0'&&pd==1)
            {
                pd=1;
                continue;
            }
            else
            {
                printf("%c",a[i]);
                pd=0;
            }    
        }    
    }
    return 0;
}

by 这我也是醉了 @ 2016-11-14 20:41:08

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
int a;
int main() {
    cin>>a;
    cout<<a%10;
    a=a/10;
    cout<<a%10;
    a=a/10;
    cout<<a<<endl;
    return 0;
}

by 这我也是醉了 @ 2016-11-14 20:41:53

100分啦!


|