Wildchesse @ 2020-08-05 10:27:26
#include <bits/stdc++.h>
using namespace std;
int main()
{
string a;
cin>>a;
int s=0;
if(a[0]=='-')
{
cout<<'-';
s=1;
}
if(a[a.size()]!='0')
{
cout<<a[a.size()];
}
for(int i=a.size()+1;i!=s;i--)
{
cout<<a[i];
}
// cout<<endl;
return 0;
}
by Steven__Chen @ 2020-08-05 10:34:22
a[a.size()]
,这不明摆着的越界吗
by yyandy @ 2020-08-05 10:36:42
所以你在写什么?
by guoxinyugz @ 2020-08-05 10:40:16
这题直接用数计算不香吗,搞什么奇奇怪怪的字符串
#include<cstdio>
int n,x;
bool w=0;
int main()
{
scanf("%d",&n);
if(n<0)
{
printf("-");
n=-n;
}
else if(n==0)
{
printf("0");
return 0;
}
while(n>0)
{
x=n%10;
if(x||w)
{
printf("%d",x);
w=1;
}
n=n/10;
}
return 0;
}
by yyandy @ 2020-08-05 10:41:49
#include <bits/stdc++.h>
using namespace std;
int main(){
string a;cin>>a;
int s=0,k=a.length()-1;
if(a[0]=='-'){cout<<'-';s=1;}
while (a[k]=='0')--k;
for(int i=k;i>=s;i--)cout<<a[i];
return 0;
}
这样也可以啊..
by a_xiao @ 2020-08-05 16:41:38
#include<iostream>
using namespace std;
int main()
{
int j=9;
int n;
int m[10]={0};
cin>>n;
if(n<0)
cout<<"-";
if(n==0)
{
cout<<0;
return 0;
}
for(int i=1;i<=10;i++)
{
m[i-1]=n%10;
n/=10;
}
int i=0;
if(m[0]==0)
{
for(i=0;i<=10;++i)
{
if(m[i]!=0)
{
break;
}
}
}
if(m[9]==0)
{
for(j=9;j>=0;--j)
{
if(m[j]!=0)
{
break;
}
}
}
for(int i=0;i<10;i++)
{
if(m[i]<0)
{
m[i]-=2*m[i];
}
}
for(;i<=j;i++)
{
cout<<m[i];
}
return 0;
}
by lynn10 @ 2020-08-29 22:50:22
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c=0,num=0;
cin>>a;
if(a<0)
{
cout<<"-";
a=-a;
}int tem=a;
while(tem>0)
{
tem/=10;
num++;
}
while(a>0)
{
b=a%10;
c+=b*pow(10,num-1);
num--;
a/=10;
}
cout<<c;
}
这样也行