#include <bits/stdc++.h> #define debuga(v, i) cout << #v << "[" << i << "]" << " = " << v[i] << '\n'; #define debug(x) cout << #x << " = " << x << '\n'; using namespace std; const int N = 32768; vector<int> v; void fun(int n, int x) { v.reserve(100); while (n) { if (n % x >= 10) { v.push_back((n % x - 10) + 'A'); } else v.push_back(n % x); n /= x; } reverse(v.begin(), v.end()); for (int i = 0; i < v.size(); i ++ ) { if (v[i] >= 10) { cout << (char)v[i]; } else cout << v[i]; } v.clear(); } void solve() { int n, x; while (cin >> n >> x) { if (n == 0) { cout << 0 << '\n'; return ; } else if (n < 0) { cout << '-'; fun(-n, x); cout << '\n'; } else { fun(n, x); cout << '\n'; } } } int main() { ios::sync_with_stdio(false); cin.tie(0); int T = 1; // cin >> T; while (T --) { solve(); } return 0; }
0.0分
0 人评分
printf基础练习2 (C语言代码)浏览:955 |
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:575 |
水仙花 (C语言代码)浏览:1164 |
文科生的悲哀 (C语言代码)浏览:1552 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:561 |
愚蠢的摄影师 (C++代码)浏览:981 |
A+B for Input-Output Practice (VI) (C语言代码)浏览:575 |
1128题解(返回值为数组的情况)浏览:571 |
矩形面积交 (C++代码)浏览:1206 |
循环入门练习5 (C语言代码)浏览:916 |