REx2341 @ 2024-09-29 14:34:40
using namespace std; int main() { string a; cin>>a; if(a.length()==1&&a[0]=='0') { cout<<0; } else { if(a[0]=='-') { cout<<'-'; } for(int i=a.length(); i>=0 ; i--) { if(a[a.length()-1]=='0') { a[a.length()-1]=a[a.length()+1]; } } for(int i=a.length(); i>=0 ; i--) { if(a[a.length()-1]=='0') { cout<<0; return 0; } } for(int i=a.length(); i>=0 ; i--) { if(a[i]>='0'&&a[i]<='9') {
cout<<a[i];
}
}
}
return 0;
}
by ye_you @ 2024-09-29 14:52:20
用
```
代码
```
by zhangjiahe__ @ 2024-09-29 14:52:34
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;
int n, s;
int main()
{
cin >> n;
while(n)
{
s = s * 10 + n % 10;
n /= 10;
}
cout << s;
return 0;
}
每次取最后一位,这样就行了,不用字符串 @REx2341
by REx2341 @ 2024-09-30 20:25:32
@zhangjiahe__ 谢谢