1 条题解
-
0
#include <bits/stdc++.h> //常规版 using namespace std; const int N = 1010; char s[N]; int a[N], b[N], cti[150], itc[150]; int main() { for (char i = '0'; i <= '9'; i++) cti[i] = i - '0', itc[i - '0'] = i; for (char i = 'A'; i <= 'Z'; i++) cti[i] = i - 'A' + 10, itc[i - 'A' + 10] = i; for (char i = 'a'; i <= 'z'; i++) cti[i] = i - 'a' + 36, itc[i - 'a' + 36] = i; int n, m; while (scanf("%d%s%d", &n, s + 1, &m) != EOF) { int len = strlen(s + 1); for (int i = 1; i <= len; i++) a[len - i + 1] = cti[s[i]]; int slen = 0; while (len) { int x = 0; for (int i = len; i >= 1; i--) { int t = x * n + a[i]; x = t % m; a[i] = t / m; } while (!a[len] && len >= 1) len--; s[++slen] = itc[x]; } for (int i = slen; i >= 1; i--) printf("%c", s[i]); puts(""); } return 0; }#include <bits/stdc++.h> //高精度版 using namespace std; typedef long long LL; const int N = 1010; char s1[N], s2[N]; int cti[150], itc[150]; struct node { int len, a[N]; node() { len = 1; memset(a, 0, sizeof(a)); } }; node operator+(node n1, int x) { node no; no = n1; no.a[1] += x; for (int i = 1; i <= no.len; i++) { no.a[i + 1] += no.a[i] / 10; no.a[i] %= 10; } int i = no.len; while (no.a[i + 1] > 0) { i++; no.a[i + 1] += no.a[i] / 10; no.a[i] %= 10; } while (i > 1 && no.a[i] == 0) i--; no.len = i; return no; } node operator*(node n1, int x) { node no; no.len = n1.len; for (int i = 1; i <= no.len; i++) no.a[i] = n1.a[i] * x; for (int i = 1; i <= no.len; i++) { no.a[i + 1] += no.a[i] / 10; no.a[i] %= 10; } int i = no.len; while (no.a[i + 1] > 0) { i++; no.a[i + 1] += no.a[i] / 10; no.a[i] %= 10; } while (i > 1 && no.a[i] == 0) i--; no.len = i; return no; } int tx; node operator/(node n1, int x) { node no; int t = 0; no.len = n1.len; for (int i = n1.len; i >= 1; i--) { t = t * 10 + n1.a[i]; no.a[i] = t / x; t = t % x; } int i = no.len; while (i > 1 && no.a[i] == 0) i--; no.len = i; tx = t; return no; } int main() { for (char c = 'A'; c <= 'Z'; c++) cti[c] = c - 'A' + 10, itc[c - 'A' + 10] = c; for (char c = 'a'; c <= 'z'; c++) cti[c] = c - 'a' + 36, itc[c - 'a' + 36] = c; for (char c = '0'; c <= '9'; c++) cti[c] = c - '0', itc[c - '0'] = c; int n, m; while (scanf("%d%s%d", &n, s1 + 1, &m) != EOF) { node no; int len1 = strlen(s1 + 1); for (int i = 1; i <= len1; i++) { no = no * n; no = no + cti[s1[i]]; } int len2 = 0; while (!(no.len == 1 && no.a[1] == 0)) { no = no / m; s2[++len2] = tx; } for (int i = len2; i >= 1; i--) printf("%c", itc[s2[i]]); printf("\n"); } return 0; }
- 1
信息
- ID
- 896
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- 5
- 标签
- 递交数
- 105
- 已通过
- 41
- 上传者