#include #include using namespace std; long long abs(long long num) { if (num < 0) { return -num; } else { return num; } } int main() { char typ[100]; int base; char inp[100]; long long num; string res; scanf(" %c", typ); while (typ[0] != 'e') { if (typ[0] == 'f') { scanf("%c%c%c%d %s", typ+1, typ+2, typ+3, &base, inp); num = 0; for (int i = 0; inp[i] != '\0'; i ++) { num *= base; num += inp[i] - '0'; } printf("%lld\n", num); } else { scanf("%c%d %lld", typ+1, &base, &num); base *= -1; res = ""; int i = 0; while (num != 0) { for (int j = 0; j < base; j ++) { if (i % 2 == 0) { if ((num - j) % base == 0) { res = (char)('0' + j) + res; num -= j; break; } } else { if ((num + j) % base == 0) { res = (char)('0' + j) + res; num += j; break; } } } num /= base; i += 1; } if (res == "") res = "0"; printf("%s\n", res.c_str()); } scanf(" %c", typ); } return 0; }