70分,c++上运行没有问题

P1307 [NOIP2011 普及组] 数字反转

bacfdml @ 2024-12-21 12:16:11

Subtask #0的 #7 #9 #Subtask #0的 #7 #9 #10和Subtask #1 的 #1 都有问题

#include <bits/stdc++.h>
using namespace std;
int main()
{
 int n,u,x=1;
 cin>>n;
 while(n)
 {
  u=n%10;
  n/=10;
  if(x==1)
  {
   if(u==0)
    continue;
  }
  else
  {
   if(u<0)
    u=-u;
   else
   if(u==0)
    continue;
  }
  cout<<u;
  x++;
 }
 return 0;
}

by rzh01014 @ 2024-12-21 12:32:30

删除前导0时,把中间所有0删了


by rzh01014 @ 2024-12-21 12:37:30

#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,u,x=1;
    cin>>n;
    if(n==0) cout<<0;
    if(n<0) cout<<"-";
    while(n) {
        u=n%10;
        n/=10;
        if(x&&u==0) continue;
        else x=0;
        if(u<0) u=-u;
        cout<<u;
    }
    return 0;
}

by rzh01014 @ 2024-12-21 12:41:31

@bacfdml


|