@[liruizhou123](/user/1053122) 零的问题,不是所有的零都需要过滤掉,中间的零就不能扔掉
by zhongboxuan123 @ 2023-09-06 19:14:32
```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
string a;
cin>>a;
int len;
bool flag=false;
len=a.length();
if(a=="0"){ cout<<a; return 0; }
if(a[0]=='-')cout<<'-';
for(int i=len-1;i>=0;i--){
if(a[i]!='-' && (a[i]!='0'||(a[i]=='0'&&flag==true))){
cout<<a[i];
if(!flag) flag=true;
}
}
}
```
by Stasis_ @ 2023-09-06 19:15:35
还有本身就只有一个0的情况
by Stasis_ @ 2023-09-06 19:16:17
@[liruizhou123](/user/1053122)
hack 数据
```
101
```
应该输出
```
101
```
而你的代码输出
```
11
```
那你应该先将这个反转的数算出来然后直接输出就行了。那么可以利用个 $ n $ ,将反转的数记录下来。计算式子: $ n=n*10+a_i $
by dongshucheng @ 2023-09-06 19:26:38
把 if(a[i]!='-' && a[i]!='0') 改成 if(a[i]!='-' && a[len-1]!='0') 试试
by Golden_Little_Tiger @ 2023-10-01 17:16:55