80分求救,为什么-5290000我去不了0

P1307 [NOIP2011 普及组] 数字反转

qilingwu @ 2018-10-03 09:31:16

#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std;
int main()
{
  long long int n;
  cin>>n;
  if(n==0)
  {
     cout<<0;
     return 0;
  }
  if(n<0)
  {  
     cout<<"-";
     n=-n;
  }
  if(n%10==0){n/=10;}
  while(n>0)
  {
      cout<<n%10;
      n/=10;
  }
  return 0;
}

by WA鸭鸭 @ 2018-10-03 09:32:54

@qilingwu -5290000%10=-0


by WA鸭鸭 @ 2018-10-03 09:33:38

@qilingwu 其实是您去零只去了一次


by qilingwu @ 2018-10-03 09:33:51

@WA鸭鸭 负数处理过了,变成了5290000 然后应该是可以取零的呀


by WA鸭鸭 @ 2018-10-03 09:34:11

@qilingwu 用while(n%10==0)n/=10;


by qilingwu @ 2018-10-03 09:34:23

@WA鸭鸭 蟹蟹大佬,确实是这样我写成if了orz


by WA鸭鸭 @ 2018-10-03 09:34:51

@qilingwu 我刚刚只是玩浮点数的梗


by WA鸭鸭 @ 2018-10-03 09:35:08

@qilingwu 不用写


by WA鸭鸭 @ 2018-10-03 09:40:19

不用谢


by 朱翘楚 @ 2019-07-24 14:25:02

if


|