两种方法
1.转换为字符串后翻转输出
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin>>n;
string s;
s = to_string(n);
reverse(s.begin(),s.end());
cout<<s;
}
2.直接将数字翻转后输出
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin>>n;
int ans=0;
while(n>0){
ans=10*ans+n%10;
n/=10;
}
cout<<ans;
}
}

京公网安备 11010502036488号