题意:给你两个 $ K $ 进制数 $ A $ 和 $ B $,将其转化为十进制,并输出二者的乘积。
思路:低位往高位的权重依次为 $ K^0, K^1, \cdot\cdot\cdot K^n $,若这一位是 $ 1 $,就把权重累加起来,最后计算乘积即可。
代码:
#include <bits/stdc++.h> #define L(i, j, k) for (int i = (j); i <= (k); i++) #define R(i, j, k) for (int i = (j); i >= (k); i--) #define i64 long long inline i64 read() { bool sym = false; i64 res = 0; char ch = getchar(); while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar(); while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar(); return sym ? -res : res; } int main() { int k = read(); std::string s, t; std::cin >> s >> t; i64 x = 0, y = 0, base1 = 1, base2 = 1; R (i, s.size() - 1, 0) { x += (s[i] - '0') * base1; base1 *= k; } R (i, t.size() - 1, 0) { y += (t[i] - '0') * base2; base2 *= k; } printf("%lld\n", x * y); return 0; }
标签:13,ch,cdot,res,08,i64,base1,base2,2023 From: https://www.cnblogs.com/LDUyanhy/p/17627332.html题意: