20分自闭

P1307 [NOIP2011 普及组] 数字反转

星宿未泯 @ 2020-12-30 18:34:26

求助大佬

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
    int n,m,b,g,s;
    cin>>n;
    if(n==0)
     cout<<0;
    if(n<0)
    {
     b=ceil(1.0*n/100);
     s=ceil(1.0*(n-b*100)/10);
     g=n-b*100-s*10;
     cout<<"-"<<abs(g)*100+abs(s)*10+abs(b);
    }
    if(n>0)  
    {
     b=floor(n/100);
     s=floor((n-b*100)/10);
     g=n-b*100-s*10;
     cout<<g*100+s*10+b;
    }
    return 0;
}

by UperFicial @ 2020-12-30 18:39:07

@星宿未泯 至少应该一层循环来翻转吧


by CGDGAD @ 2020-12-30 18:49:18

没说一定是三位数


by guiyonghe123 @ 2021-01-09 21:15:13

我也这样


by 许江一墨 @ 2021-02-23 13:54:15

楼上的楼上正解。


|