一遍AC,走过路过千万不可错过

P1307 [NOIP2011 普及组] 数字反转

焚魂 @ 2019-07-07 22:42:40

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int length(int tx);
int main()
{
    int a;
    cin>>a;
    if(a<0)
    {
        cout<<"-";
        a=abs(a);
    }
    while(a%10==0)
    a/=10;
    int l=length(a);
    for(int i=l;i>=1;i--)
    {
        cout<<a%10;
        a/=10;
    }
    return 0;
}
int length(int tx)
{
    int lena=0,tt=tx;
    while(tt)
    {
        tt/=10;
        lena++;
    }
    return lena;
}

by 焚魂 @ 2019-07-07 22:44:29

while(a%10==0)
    a/=10;

这一步是删除这个数后面的多余的0。剩下的就很好理解啦


by 小粉兔 @ 2019-07-07 22:44:41

一遍AC,走过路过千万不可错过

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int length(int tx);
int main()
{
    int a;
    cin>>a;
    if(a<0)
    {
        cout<<"-";
        a=abs(a);
    }
    while(a%10==0)
    a/=10;
    int l=length(a);
    for(int i=l;i>=1;i--)
    {
        cout<<a%10;
        a/=10;
    }
    return 0;
}
int length(int tx)
{
    int lena=0,tt=tx;
    while(tt)
    {
        tt/=10;
        lena++;
    }
    return lena;
}

by 小粉兔 @ 2019-07-07 22:44:57

while(a%10==0)
    a/=10;

这一步是删除这个数后面的多余的0。剩下的就很好理解啦


by 小小小朋友 @ 2019-07-07 22:45:25

左转题解


by 枫初音斗颂皮 @ 2019-07-07 23:01:10

举报成功


by 1saunoya @ 2019-07-08 06:36:28

要不我们举报兔队吧 @小粉兔


by 1saunoya @ 2019-07-08 06:37:18

// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define f(i,j,n) for(int i=j;i<=n;i++)
#define F(i,j,n) for(int i=j;i>=n;i--)
using namespace std;
int a[1005];
int main()
{
    string s;
    cin>>s;
    if(s[0]=='-')
    {
        cout<<'-'; 
        int length=s.length()-1;
        f(i,1,length) a[i]=s[i]-'0';
        while(a[length]==0) length--; 
        F(i,length,1)  cout<<a[i];
    }
    else
    {
        int length=s.length();
        f(i,0,s.length()-1) a[i+1]=s[i]-'0';
        while(a[length]==0) length--;
        F(i,length,1)  cout<<a[i];
    }
    return 0;
}

by leozhang @ 2019-07-08 06:59:50

粉蒸兔队蒸粉兔


by 灵光一闪 @ 2019-07-08 13:39:00

@小粉兔 您可以选一个qaq


by ldto @ 2019-10-11 13:16:21

才入门,不过就是蒟蒻了!


| 下一页