lihongxing @ 2024-09-16 17:47:49
#include<bits/stdc++.h>
using namespace std;
int main()
{
string a;
cin>>a;
bool f=1;
int i=a.size()-1;
if(a[0]=='-')
cout<<'-',i--;
for(i;i>=0;i--)
{
if(f==true&a[i]==false)
{
}else
f==false;
if(f!=true)
cout<<a[i];
}
}
by lxr_Galaxy @ 2024-09-16 17:54:58
@lihongxing e...有点没看懂你在写什么,参考下我的代码吧
#include<bits/stdc++.h>
using namespace std;
string s;
int n,in=0,i;
int main(){
cin>>s;
int len=s.size();
if(s[0]=='-')in=1;
for(i=len-1;i>=in;i--){
n=n*10+s[i]-48;
}
if(in)cout<<"-";
cout<<n;
}
by lxr_Galaxy @ 2024-09-16 17:57:29
@lihongxing ao,我懂了,你代码里面a[i]是用来判断a[i]项是否为0对吗?但你有没有想过第i项为0但是i-1项不为0呢?而且输入在字符串判断时却是在判断是不是等于整型的0(或者说是布尔值)
by wangshengchen @ 2024-09-28 14:14:32
@lihongxing 这是我的思路
#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
if(n==0){
cout<<0;
return 0;
}
if(n<0){
n=-n;
cout<<"-";
}
while(n%10==0) n/=10;
int m=0;
while(n){
m=m*10+n%10;
n/=10;
}
cout<<m;
return 0;
}