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

    http://acm.hdu.edu.cn/showproblem.php?pid=2031

    今天下午翻到11页突然发现我的水题系列还有好多没有做,呵呵,一试手感还不错,只是一个小小的错误,wa。。。。本题就是利用assic码值,用字符串读出更方便吧,不过一改就对了,感觉真不错。。。

    #include <stdio.h>

    #include <string.h>

    #include <stdlib.h>

    int main()

    {

        int m,n,r,a[1000],k,flag;

        while(scanf("%d%d",&n,&m)!=EOF)

        {

              k=0;flag=0;

              if(n<0)

              {

                     flag=1;n=-n;

              }

              r=n%m;

              while(n)

              {   

                  if(r<10)

                   a[k++]=r+48;

                   if(r>=10)

                   a[k++]=r+55;

                   n=n/m;

                   r=n%m;

              }

              if(flag==1)

              printf("-");

              for(int i=k-1;i>=0;--i)

              printf("%c",a[i]);

              printf("\n");

        }

       // system("pause");

        return 0;

    }

  • 相关阅读:
    Examples
    Examples
    Examples
    Examples
    Examples
    Examples
    Examples
    Examples
    Examples
    如何把随机数或者对象添加到ArrayList集合
  • 原文地址:https://www.cnblogs.com/yuelingzhi/p/2126342.html
Copyright © 2011-2022 走看看