Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
October 10, 2021 04:51 pm GMT

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

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To