如何用10隻實驗鼠檢驗出1000個藥瓶中哪個有毒藥?

來源:互聯網
上載者:User

 

00     第0瓶

1    1

0     2

1    3

0     4

1     5

0    6

1     7

public class Base {       /**       * 將數轉為任意進位       * @param num       * @param base       * @return       */      public String baseString(int num,int base){           if(base > 16){               throw new RuntimeException("進位數超出範圍,base<=16");           }           StringBuffer str = new StringBuffer("");           String digths = "0123456789ABCDEF";           Stack<Character> s = new Stack<Character>();           while(num != 0){               s.push(digths.charAt(num%base));               num/=base;           }           while(!s.isEmpty()){               str.append(s.pop());           }           return str.toString();       }       /**       * 16進位內任意進位轉換       * @param num       * @param srcBase       * @param destBase       * @return       */      public String baseNum(String num,int srcBase,int destBase){           if(srcBase == destBase){               return num;           }           String digths = "0123456789ABCDEF";           char[] chars = num.toCharArray();           int len = chars.length;           if(destBase != 10){//目標進位不是十進位 先轉化為十進位               num = baseNum(num,srcBase,10);           }else{               int n = 0;               for(int i = len - 1; i >=0; i--){                   n+=digths.indexOf(chars[i])*Math.pow(srcBase, len - i - 1);               }               return n + "";           }           return baseString(Integer.valueOf(num),destBase);       }   }  

轉載請標明出處:http://blog.csdn.net/u012027907
 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.