Cuimenghao @ 2024-02-06 17:48:04
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;
int main() {
string n;
cin >> n;
int m;
m = n.length();
int a[100];
if (n[0] == '-') {
for (int o = m -1, j = 1; o >= 1; o--, j++) {
a[j] = n[o];
}
a[0] = '-';
}else{
for(int i=m-1,j=0;i>=1;i--,j++){
a[j]=n[i];
}
}
for (int i = 0; i < m; i++) {
if(a[i]!=0){
cout<<a[i];
}
}
return 0;
}
by WilliamFranklin @ 2024-02-06 17:51:18
@Cuimenghao a 数组应该是 char 类型吧
by WilliamFranklin @ 2024-02-06 17:57:26
for (int i = 0; i < m; i++) {
if(a[i]!=0){
cout<<a[i];
}
}
这里完全错了啊,让的是去掉前导零,不是所有的 0 啊,而且应该是 char 类型的。
by Killer_master @ 2024-02-06 18:00:59
@Cuimenghao 1.输入的有可能是0 2.不止开头有0,最后不能直接判断输出
by Cuimenghao @ 2024-02-06 18:08:08
谢谢诸位
by lunxiaotong0118 @ 2024-02-18 15:03:46
#include<bits/stdc++.h>
using namespace std;
int n,s=0;
int main()
{
cin>>n;
while(n) s=s*10+n%10,n/=10;
cout<<s;
return 0;
}