18.2.14 【水】codevs1474 十進制轉m進制
阿新 • • 發佈:2018-02-14
sed mat pos post () play 反向 分享圖片 scrip
題目描述 Description
將十進制數n轉換成m進制數 m<=16
n<=100
輸入描述 Input Description共一行
n和m
輸出描述 Output Description共一個數
表示n的m進制
樣例輸入 Sample Input樣例1:10 2
樣例2:100 15
樣例輸出 Sample Output樣例1:1010
樣例2:6A
數據範圍及提示 Data Size & Hint用反向取余法
1 #include <iostream> 2View Code#include <math.h> 3 4 using namespace std; 5 6 int main() 7 { 8 char wei[17]={‘0‘,‘1‘,‘2‘,‘3‘,‘4‘,‘5‘,‘6‘,‘7‘,‘8‘,‘9‘,‘A‘,‘B‘,‘C‘,‘D‘,‘E‘,‘F‘,‘G‘}; 9 int num[100]; 10 int m,n;//m->n; 11 cin>>m>>n; 12 int count=0; 13 while(m!=0) 14 { 15 count++;16 num[count]=m%n; 17 m/=n; 18 } 19 for(int i=count;i>0;i--) 20 { 21 cout<<wei[num[i]]; 22 } 23 cout<<endl; 24 return 0; 25 }
套路:反向取余
18.2.14 【水】codevs1474 十進制轉m進制