1 条题解
-
0
题解:进制数的展开式
思路
字符串长度为 时,下标为 的数码对应的幂次为 。
从左到右扫描字符串:
- 当前数码为
0,跳过; - 否则输出
数码*M^幂次; - 用布尔变量控制加号,避免开头或结尾多出
+。
若所有数码都是
0,输出0。复杂度
时间复杂度 ,额外空间复杂度 。
参考代码
#include <bits/stdc++.h> using namespace std; int main() { int m; string s; cin >> m >> s; bool first = true; int n = (int)s.size(); for (int i = 0; i < n; i++) { if (s[i] == '0') continue; if (!first) cout << "+"; cout << s[i] << "*" << m << "^" << n - i - 1; first = false; } if (first) cout << 0; cout << "\n"; return 0; } - 当前数码为
- 1
信息
- ID
- 5109
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 6
- 标签
- 递交数
- 37
- 已通过
- 11
- 上传者
粤公网安备44195502000195号