1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | #include <iostream> #include <algorithm> using namespace std; const int MAXL = 1000; int n, k, ans[MAXL]; int main(void) { cin >> n >> k; if (!n) cout << 0 << endl; else { int m = 0; while (n) { ans[m++] = (n % (-k) + k) % k; n = (ans[m - 1] - n) / k; } for (int i = m - 1; i >= 0; i--) cout << char(ans[i] >= 10 ? ans[i] + 'A' - 10 : ans[i] + '0'); cout << endl; } return 0; } |
假设输入的 n 在 int 范围内,k 为不小于 2 且不大于 36 的正整数,完成下面的判断题和单选题:
0 of 6 Questions completed
Questions:
You have already completed the quiz before. Hence you can not start it again.
Quiz is loading…
You must sign in or sign up to start the quiz.
You must first complete the following:
0 of 6 Questions answered correctly
Your time:
Time has elapsed
You have reached 0 of 0 point(s), (0)
Earned Point(s): 0 of 0, (0)
0 Essay(s) Pending (Possible Point(s): 0)
28、该算法的时间复杂度为O(log\(_{k}\)n)。
29、删除第 23 行的强制类型转换,程序的行为不变。
31、当输入为“100 7”时,输出为( )。
32、当输入为“-255 8”时,输出为“( )”。
33、当输入为“1000000 19”时,输出为“( )”。