[java]2015上海邀請賽 B Base64

來源:互聯網
上載者:User

標籤:

題意: 給n和一個字串(可以有空格) 求字串編碼n次後的字串

    編碼方式:字串的每個字元轉化成ASCII碼, ASCII碼轉化成8位2進位,

      將位元分割成6位為一組的(不夠的補0), 再變成十進位數 依次按照以下方式變成字母

   轉化成字母后, 若長度不是4的整數倍, 在字串後面補=

 

舉個例子, The的ASCII碼分別為84,104,101 轉成8位2進位為01010100,01101000,01100101

      分割成6位的為010101,000110,100001,100101

        十進位分別為21,6,33,37

      查得表中的字母為VGhl

因此The 編碼一次之後是VGhl

 

雖然題意很麻煩,然而代碼很簡單~兩行就夠了

代碼:

 1 import java.io.*; 2 import java.util.*; 3 import java.math.*; 4 import java.nio.charset.StandardCharsets; 5  6 public class Main 7 { 8     public static void main(String[] args) 9     {10         Scanner in=new Scanner(System.in);11         int t, ca=1;12         t=in.nextInt();13         while((t--)!=0)14         {15             int n;16             n=in.nextInt();17             String s;18             s=in.nextLine();19             s=s.substring(1);20             System.out.print("Case #" + ca + ": ");21             ca++;22             for(int i=0;i<n;i++)23             {24                 byte[] tmp=s.getBytes(StandardCharsets.US_ASCII);25                 s=Base64.getEncoder().encodeToString(tmp);26             }27             System.out.println(s);28         }29     }30 }
Base64

 

[java]2015上海邀請賽 B Base64

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.