zoukankan      html  css  js  c++  java
  • 进制转换 2031

    Problem Description

    输入一个十进制数N,将它转换成R进制数输出。
     
    Input
    输入数据包含多个测试实例,每个测试实例包含两个整数N(32位整数)和R(2<=R<=16, R<>10)。
     
    Output
    为每个测试实例输出转换后的数,每个输出占一行。如果R大于10,则对应的数字规则参考16进制(比如,10用A表示,等等)。
     
    Sample Input
    7 2 23 12 -4 3
     
    Sample Output
    111 1B -11
     
    Author
    lcy
     
    Source
     
    Recommend
    lcy   |   We have carefully selected several similar problems for you:  2029 2028 2044 2041 2040 
     
     
     
     1 #include <stdio.h>
     2 #include <string.h>
     3 
     4 void ttor(int n, int r)
     5 {
     6     if (n)
     7     {
     8         ttor(n / r, r);
     9         printf("%c", n % r > 9 ? n % r - 10 + 'A' : n % r + '0');
    10     }
    11 }
    12 
    13 int main(void)
    14 {
    15     int n;
    16     int r;
    17 
    18     while (scanf("%d%d", &n, &r) != EOF)
    19     {
    20         if (n > 0)
    21             ttor(n, r);
    22         else if (!n)
    23             putchar('0');
    24         else
    25         {
    26             putchar('-');
    27             ttor(-n, r);
    28         }
    29         putchar('
    ');
    30     }
    31 
    32     return 0;
    33 }
  • 相关阅读:
    搜索区间
    搜索插入位置
    旋转排序数组
    搜索二维矩阵
    njnja 安装
    rpmbuild打包
    snappy 安装
    mysql8 安装
    re2c安装
    make 安装
  • 原文地址:https://www.cnblogs.com/wangmengmeng/p/4621652.html
Copyright © 2011-2022 走看看