[java]2015 Shanghai Invitational B Base64

Source: Internet
Author: User
Tags base64

Test instructions: string with N and a string (can have spaces) encoded n times

Encoding: Each character of the string is converted into ASCII code, and ASCII code is converted to 8-bit 2-binary,

The binary number is divided into 6 bits (not enough for 0), and then the decimal number is converted into letters in the following way

After the conversion to a letter, if the length is not an integer multiple of 4, after the string to fill =

For example, the ASCII code of the 84,104,101 turns into 8-bit 2 binary for 01010100,01101000,01100101

Divided into 6 bits for the 010101,000110,100001,100101

The decimal is 21,6,33,37, respectively.

The letters in the table are VGHL.

So the code once was VGHL

Although the test instructions is very troublesome, but the code is very simple ~ two lines is enough

Code:

1 ImportJava.io.*;2 ImportJava.util.*;3 Importjava.math.*;4 Importjava.nio.charset.StandardCharsets;5 6  Public classMain7 {8      Public Static voidMain (string[] args)9     {TenScanner in=NewScanner (system.in); One         intT, Ca=1; At=in.nextint (); -          while((t--)!=0) -         { the             intN; -n=in.nextint (); - String S; -s=in.nextline (); +S=s.substring (1); -System.out.print ("Case #" + Ca + ":"); +ca++; A              for(inti=0;i<n;i++) at             { -                 byte[] tmp=s.getbytes (STANDARDCHARSETS.US_ASCII); -s=Base64.getencoder (). encodetostring (TMP); -             } - System.out.println (s); -         } in     } -}
Base64

[java]2015 Shanghai Invitational B Base64

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.