Kirisama @ 2021-11-01 23:41:25
#include<iostream>
using namespace std;
int main()
{int a,n,z;
cin>>a;
if(a>0)
{
while(a%10==0)
{a/=10;
}
for(int m=a;m%10!=0;m=a)
{m%=10;
cout<<m;
a/=10;
}
}
if(a<0){
if(a%10!=0)
a=-1*a;
while(a%10==0)
{a/=-10;
}
for(int m=a;m%10!=0;)
{m%=10;
cout<<-m;
break;
}
for(n=a/10;n%10!=0;n/=10){
z=n%10;
cout<<z;
}
}
if(a==0)
cout<<a%10;
return 0;
}
by Jiao_Xie @ 2021-11-01 23:52:47
那个...可以缩进一下吗?我亲爱的然比
by Jiao_Xie @ 2021-11-01 23:59:38
没事我现在缩好了
by Jiao_Xie @ 2021-11-02 00:03:22
1.循环终止条件应为m>0,不然会在末尾多输出0
2.a<0的部分有很大问题,可以直接复制a>0处的代码,在前面输出负号
by Jiao_Xie @ 2021-11-02 00:05:22
说错了/gg
还有锅,我太捞了
by Jiao_Xie @ 2021-11-02 00:09:17
在执行a>0的操作后,会把a的值变为0,此时最后一个if条件会触发输出0
by Jiao_Xie @ 2021-11-02 00:10:32
代码:
#include<iostream>
using namespace std;
int main()
{
int a,n,z;
cin>>a;
if(a>0)
{
while(a%10==0) {a/=10;}
for(int m=a;a>0;m=a)
{
m%=10;
cout<<m;
a/=10;
// printf("%d\n",a);
}
}
else if(a<0)
{
a=-a;
printf("-");
while(a%10==0) {a/=10;}
for(int m=a;a>0;m=a)
{
m%=10;
cout<<m;
a/=10;
}
}
else if(a==0) cout<<a;
return 0;
}
by Kirisama @ 2021-11-02 12:26:47
@Jiao_Xie 谢谢大佬!以后注意awa
by EdwardShi @ 2021-11-10 21:42:31
其实还有种方法!你可以借鉴一下!
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n,s;
bool flag=0;
cin>>n;
if (n==0){
cout<<0;
return 0;
}
if (n<1){
cout<<"-";
n=abs(n);
}
while (n>0){
s=n%10;
n/=10;
if (s!=0 and flag==0){
flag=1;
}
if (flag==1) cout<<s;
}
return 0;
}