An Interest In:
Web News this Week
- March 21, 2024
- March 20, 2024
- March 19, 2024
- March 18, 2024
- March 17, 2024
- March 16, 2024
- March 15, 2024
LnipLesson4
include
include
include
include
typedef long long ll;
int main2() {
int n = 0;
int base = 10;
std::cin >> n >> base;
std::string result;
while (n > 0) {
char c = char(n % base) + '0';
n /= base;
result += c;
}
std::reverse(result.begin(), result.end());
std::cout << result << std::endl;
}
int CharToInt(char c) {
if (c >= '0' && c <= '9') return c - '0';
if (c >= 'A' && c <= 'Z') return c - 'A' + 10;
if (c >= 'a' && c <= 'z') return c - 'a' + 10;
throw std::runtime_error("Very Bad Symbol");
}
ll Bebra(std::string& s, int base) {
ll result = 0;
// .
// result = (((s[0]10 + s[1]) 10 + s[2])*10 + s[3])*10 + ... + s[l-1];
for (int i = 0; i < s.length(); ++i) {
result = result * base + CharToInt(s[i]);
}
return result;
}
int main() {
std::string s;
int base = 10;
std::cin >> s >> base;
try {
std::cout << Bebra(s, base) << std::endl;
} catch (std::runtime_error& e) {
std::cout << e.what();
}
return 0;
}
Original Link: https://dev.to/joinmoin0002/lniplesson4-2el
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To