@[liyijie](/user/705833)
有没有可能你的 $k$ 值为 0
改为
```cpp
while(k%10==0 && k!=0) k/=10;
```
by c1120241919 @ 2022-08-31 21:40:23
解决求关注
by c1120241919 @ 2022-08-31 21:40:55
@[c1120241919](/user/686053)
加特判也行
```cpp
#include<bits/stdc++.h>
using namespace std;
long long s[11],n,k=0,a=1;
int main()
{
cin>>n;
if(n==0)
{
cout<<"0";
return 0;
}
for(int i=1;i<=10;i++) s[i]=n/a%10,a*=10;
a=1000000000;
for(int i=1;i<=10;i++) k+=s[i]*a,a/=10;
while(k%10==0) k/=10;
cout<<k;
return 0;
}
```
by liyijie @ 2022-08-31 22:00:12
@[liyijie](/user/705833) 考虑负数
by hdkghc @ 2022-09-01 07:12:14
我以前写的:
```cpp
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int weishu(int x)
{
char* s=(char*)(malloc(sizeof(char*)));
sprintf(s,"%d",x);
return strlen(s);
}
int zsfz(int x)
{
int mask=weishu(x);
int t=0;
do{
int d=x%10;
t = t*10+d;
x/=10;
}while(x>0);
return t;
}
int main()
{
int x;
bool less=0;
cin>>x;
if(x<0) less++;
x=zsfz((less)?-x:x);
if(less) cout<<'-';
cout<<x;
return 0;
}
```
by hdkghc @ 2022-09-01 07:12:44
~~有点垃圾,只会用拼音~~
by hdkghc @ 2022-09-01 07:15:35
@[hdkghc](/user/346134)
但是我加完特判就过了诶
by liyijie @ 2022-09-01 12:14:52