This is simply a human work simulation - exactly reproducing how you do it by hand. Nothing special. You'd better put each step on a paper to make everything clear. Reference: http://blog.csdn.net/rappy/article/details/1737671

My code passed all 6 test cases. Yay..

//

#include <iostream>
#include <cstring>
#include <vector>
#include <cmath>
using namespace std; char GetDigitChar(int val)
{
if(val >= && val <= ) return val + '';
else if(val >= && val < ) return val - + 'A';
return '\0';
} int GetDigitVal(char c)
{
c = toupper(c);
if( c >= '' && c <= '') return c - '';
else if(c >= 'A' && c <= 'Z') return c - 'A' + ;
return ;
} void num_conv(string &str, int r, int s)
{
int strLen = str.length(); // Convert string to val first
vector<int> origVal;
origVal.reserve(strLen);
for(int i = ; i < strLen; i ++)
{
origVal.push_back(GetDigitVal(str[i]));
} // Go
vector<char> ret; int currStartInx = ;
bool bAllDone = false;
while(currStartInx < strLen && !bAllDone)
{
// cout << "Start from " << currStartInx << endl;
for(int i = currStartInx; i < strLen;i++)
{
// cout << "\t Curr Digit: " << origVal[i] << endl;
int quo = origVal[i] / s;
int rem = origVal[i] % s;
// cout << "\t Quo: " << quo << " Rem: " << rem << endl; origVal[i] = quo;
// The digit to record
if(i == strLen - )
{
ret.push_back(GetDigitChar(rem));
// cout << "!" << GetDigitChar(rem) << endl;
bAllDone = (currStartInx == (strLen - ) && quo == )? true: false;
break;
} // Add remainer to next digit
if(rem > )
{
// cout << "\tAdding rem " << r * rem << " = ";
origVal[i+] += r * rem;
// cout << origVal[i+1] << endl;
} if(i == currStartInx)
{
currStartInx += quo == ? : ;
}
}// for
}// while // Output
for(int i = ret.size() - ; i >=; i --)
{
cout << ret[i];
}
cout << endl;
} int main()
{
int runcnt = ;
cin >> runcnt;
while(runcnt--)
{
string strnum;
int r, s;
cin >> strnum >> r >> s;
num_conv(strnum, r, s);
}
return ;
}

最新文章

  1. 我与ADO.NET二三事
  2. mosquitt win32
  3. 学霸网站-Beta版本发布说明
  4. 【实例】html5-canvas中实现背景图片的移动
  5. IOS-Social.framework
  6. hdu2255 二分图最大权配KM
  7. linux中非root用户使用wireshark进行抓包
  8. C#集合--ICollection接口和IList接口
  9. 让IE8支持HTML5及canvas功能!
  10. C语言初学者代码中的常见错误与瑕疵(14)
  11. JavaScript基于对象(面向对象)&lt;一&gt;类和对象
  12. eXtremeDB
  13. 记React+.NetCore API实现动态列导出
  14. OLE:对象的类没有在注册数据库中注册
  15. ESP8266小知识与注意事项
  16. word,excel,ppt,txt转换为 PDF
  17. Globecom 2018 投稿过程
  18. JDK10源码阅读--String
  19. 对于League of Legends的分析
  20. css---点击显示和隐藏

热门文章

  1. win7 一些快捷系统工具命令
  2. php中读取文件内容的几种方法
  3. 11. Container With Most Water
  4. kuangbin_ShortPath G (POJ 1502)
  5. 【转】iOS websocket 及时通讯实现
  6. dotnetConf
  7. Oracle数据库——Scheduler Job
  8. VC++多线程编程
  9. 基于window.onerror事件 建立前端错误日志
  10. $.browser.msie 报错 null