spessert @ 2024-03-16 09:47:23
#include<iostream>
using namespace std;
char num[15];
int main()
{
string s;
cin>>s;
if(s[0]=='-'){
num[0]='-'; //设置num[0]为符号位
int ls=s.size()-1;
for(int i=1;i<=ls;i++){
num[i]=s[i];
}
cout<<'-';
for(int i=ls;i>=1;i--){
if(num[i]=='0') continue;
cout<<num[i];
}
}else{
int ls=s.size();
for(int i=0;i<ls;i++){
num[i]=s[i];
}
for(int i=ls-1;i>=0;i--){
if(num[i]=='0'&&i>0) continue;
cout<<num[i];
}
}
return 0;
}
by 13600887213yuan @ 2024-03-16 09:55:24
用循环就行了,不用那么麻烦 int a,c=0; cin>>a; for(;;) {
if(a==0)
{
cout<<c;
break;
}
else
{
int b;
b=a%10;
a/=10;
c*=10;
c+=b;
}
}
return 0;
by 13600887213yuan @ 2024-03-16 09:56:15
用循环就行了,不用那么麻烦
int a,c=0;
cin>>a;
for(;;)
{
if(a==0)
{
cout<<c;
break;
}
else
{
int b;
b=a%10;
a/=10;
c*=10;
c+=b;
}
}
return 0;
}
by spessert @ 2024-03-22 12:20:47
@13600887213yuan 懂了,感谢!!!