using System;
using System.Collections.Generic;
class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
* 进制转换
* @param M int整型 给定整数
* @param N int整型 转换到的进制
* @return string字符串
*/
public string solve (int M, int N) {
// write code here
if (N < 2)
return M.ToString();
int nFH = 1;
if (M < 0) {
nFH = -1;
M = Math.Abs(M);
}
List<string> listStr = new List<string>();
do {
int nS = M % N;
string strnS = nS > 10 ? ((char)((nS / 10) * 'A' + nS % 10)).ToString() :
nS.ToString();
listStr.Add(strnS);
M = M / N;
} while (M / N > 0);
listStr.Add(M.ToString());
listStr.Reverse();
return nFH > 0 ? string.Join("", listStr) : "-" + string.Join("", listStr);
}
}