zoukankan      html  css  js  c++  java
  • 1474 十进制转m进制

    题目描述 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

    用反向取余法

    反向取余用栈来写极方便的。

    附AC代码:

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm> 
     5 #include<stack>
     6 using namespace std;
     7 
     8 int main(){
     9     char ch[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
    10     int m,n;
    11     stack<char> s;
    12     cin>>m>>n;
    13     while(m>=n){
    14         s.push(ch[m%n]);
    15         m=m/n;
    16     }
    17     s.push(ch[m]);
    18     while(!s.empty()){
    19         cout<<s.top();
    20         s.pop();
    21     }
    22     cout<<endl;
    23     return 0;
    24 }
  • 相关阅读:
    leetcode931
    leetcode1289
    leetcode1286
    poj Meteor Shower
    noip杂题题解
    noip2007部分题
    NOIP Mayan游戏
    某模拟题题解
    codevs 1423 骑士
    noip 邮票面值设计
  • 原文地址:https://www.cnblogs.com/Kiven5197/p/5659220.html
Copyright © 2011-2022 走看看