首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

HDU 2031之十进制转N进制

2012-12-26 
HDU 2031之10进制转N进制#includeiostream#includestringusing namespace stdchar *str[] {0,1,

HDU 2031之10进制转N进制

#include<iostream>#include<string>using namespace std;char *  str[] ={"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"};int main(){    int n,m,t,i,j;    string s;    while(cin>>n>>m)    {      if(n<0)      {        cout<<'-';        n=-n;      }      while(n)      {       t=n%m;       s+=str[t];       n/=m;      }      for( i=s.length()-1, j=0;i>j;i--,j++)      {         t=s[i];         s[i]=s[j];         s[j]=t;      }      cout<<s<<endl;      s="";    } return 0  ;}

热点排行