奇安信8.16笔试
总共两题,第一题发奖金,题干错了,我已反馈,大家快去反馈!!!坑了我一个小时,A了0%
int CalulateMethodCount(int num_money) { // write code here vector<int> dp(num_money + 1, 0); dp[0] = 1; dp[1] = 1; for (int i = 2; i <= num_money; i++) { for (int j = 0; j < i; j++) { dp[i] += dp[j]; } } return dp[num_money]; }第二题输入一行字符串,里面包含undo和redo,分别代表撤销和恢复,比如:
输入 Hello undo redo World.
输出 Hello World.
用了两个栈来回倒腾,不知道为啥只过了80%
用了两个栈来回倒腾,不知道为啥只过了80%
int main() { string tmp; stack<string> a; stack<string> b; while (cin >> tmp) { if (tmp == "undo") { if (a.empty()) continue; b.push(a.top()); a.pop(); } else if (tmp == "redo") { if (b.empty()) continue; a.push(b.top()); b.pop(); } else { a.push(tmp); } if (cin.get() == '\n') break; } vector<string> t(a.size()); int idx = a.size() - 1; while (!a.empty()) { t[idx--] = a.top(); a.pop(); } for (string s : t) { cout << s << ' '; } }