11451410086_lrr @ 2024-01-22 14:09:49
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,ge,shi,bai,shu;
cin>>n;
ge=n%10;
shi=n/10%10;
bai=n/100%10;
if(n<0&&ge!=0)
shu=-(100*(ge-2*ge)+10*(shi-2*shi)+(bai-2*bai));
else if(n<0&&ge==0)
shu=-(10*(shi-2*shi)+(bai-2*bai));
else
shu=100*ge+10*shi+bai;
cout<<shu;
return 0;
}
by SugarKite @ 2024-01-22 14:21:07
题干中并没有说是3位数
by SugarKite @ 2024-01-22 14:22:44
@20110313lrr
by yanghanhang @ 2024-01-22 16:56:01
还要包括负数和0
by yanghanhang @ 2024-01-22 16:58:30
@20110313lrr 如果是230,反过来还要去0,变成32,小数末尾要省略
by 11451410086_lrr @ 2024-01-22 17:16:16
@yanghanhang
if(n<0&&ge!=0)
shu=-(100*(ge-2*ge)+10*(shi-2*shi)+(bai-2*bai));
else if(n<0&&ge==0)
shu=-(10*(shi-2*shi)+(bai-2*bai));
这是考虑的0
by 11451410086_lrr @ 2024-01-22 17:16:55
@Tzy090420 谢了