lyz2005 @ 2023-11-14 20:13:29
#include<stdio.h>
int main()
{
char a[20];
int cnt = 0;
for(;cnt < 20;cnt++)
{
scanf("%c",&a[cnt]);
if(a[cnt] == '\n')
break;
}
if(a[0] == ’-’&&a[1]=='\n'||a[0] == '-'&&a[1]=='0'&&a[2]=='\n'))
{
printf("0");
return 0;
}
int decide = 0,decide_ = 0;
if(a[0] == '-')
{
printf("-");
decide = 1;
decide_ = 1;
}
int cnt_ = cnt - 1;
if(a[cnt - 1] == '0')
decide = 1;
for(;cnt_ <= cnt-1 && cnt_ >= decide_;cnt_--)
{
if((a[cnt_] == '0' && decide != 1)||(a[cnt_] != '0')||decide == 0)
{
decide = 0;
printf("%c",a[cnt_]);
}
}
return 0;
}
by Xishuchen0912 @ 2023-11-14 22:43:55
可以这样做,Ac代码如下: cpp
using namespace std;
int main(){
int n,num=0,a;
cin>>n;
while(n!=0){
a=n%10;
n=n/10;
num=num*10+a;
}
cout<<num;
}
by lyz2005 @ 2023-11-15 19:41:15
@Xishuchen0912 好的,非常感谢!