2019唯品会秋招,整数的倒数
整数的倒数
http://www.nowcoder.com/questionTerminal/dd63c30dfef04770b5813e63f5a2615a
#include <vector> #include <string> #include <iostream> #include <stack> using namespace std; void integarBackwards() { char ch; stack<char> st; bool flag = false; while (ch = getchar()) { if (ch == '\n') { break; } if (ch == '-') { flag = true; } else { st.push(ch); } } if (flag) { st.push('-'); flag = false; } while (!st.empty()) { char topChar = st.top(); cout << topChar; st.pop(); } cout << endl; } int main() { integarBackwards(); return 0; }