zrf1170375918 @ 2019-08-20 21:01:04
#include <stdio.h>
#include <stdlib.h>
int main()
{
long int in;
int a[10]={0},i=0,pv;
scanf("%ld",&in);
pv=labs(in);
if(pv>0)
{
while(pv>0)
{
a[i]=pv%10;
pv/=10;
i++;
}
if(in<0)
{
printf("-");
}
if(a[0]!=0)
{
printf("%d",a[0]);
}
for(int j=1;j<i;j++)
{
printf("%d",a[j]);
}
}
else
{
printf("0");
}
return 0;
}
by SJC_03 @ 2019-08-20 21:07:41
@zrf1170375918
你试试这个数据:
20000
应输出:
2
你的输出:
0002
by SJC_03 @ 2019-08-20 21:08:59
您应该去除所有的前导0
by mtz_FWB @ 2019-08-20 21:18:33
long long n,w,s=0;
cin>>n;
while(n!=0){
w=n%10;
s=s*10+w;
n=n/10;
}
cout<<s;
by zrf1170375918 @ 2019-08-20 21:48:35
@SJC_03 明白了,谢谢大佬
by JamesMessi @ 2019-08-21 11:13:46
#include<bits/stdc++.h>
using namespace std;
int a[1000];
int dao(int n){
int s=0;
while (n!=0){
s=s*10+n%10;
n=n/10;
}
return s;
}
int main(){
int n;
cin>>n;
cout<<dao(n);
return 0;
}