题解 | #整数反转#
整数反转
https://www.nowcoder.com/practice/14733e0bfa9b474ba7cbe0bb2e459731
//整数反转 #include <cstdio> #include <stack> using namespace std; int main(){ int n; stack <int> stack1,stack2; scanf("%d",&n); int signal; if(n >=0 ){ signal = 1; } else{ signal = -1; } while ( n != 0){ stack1.push(n%10); n=n/10; } while ( !stack1.empty()){ stack2.push(stack1.top()); stack1.pop(); } int rev=0; while ( !stack2.empty() ){ rev = rev*10 + stack2.top(); stack2.pop(); } if (signal == 1){ printf("%d",rev); } if (signal == -1){ rev=0+rev; printf("%d",rev); } return 0; }