Huawei on-Machine test problem (digital string to binary-java)

Source: Internet
Author: User

PS: This problem just finished, full marks, can refer

/* Title: Digital string to binary binary

* Description: Enter a string of integers, convert each integer to binary number, if the third bit is "0", then output "0", if "1", then output "1".

Topic Category: Bit arithmetic

Difficulty: Beginner

Score: 60

Operating time limit: Ten Sec

Memory Limit: MByte

Stage: Application for examination

Input: A string of integers with a length of less than 1024 and integers separated by spaces

Output: 1/0 integer string, separated by spaces

Sample input: 240 0

Sample output: 0 0

Answer hint:

*/

1 ImportJava.util.Scanner;2 3  Public classMain {4 5      Public Static voidMain (string[] args) {6         7String bitstr = "";8         9Scanner cin =NewScanner (system.in);TenString str =cin.nextline (); One          ABitstr =getbitstring (str); -          - System.out.println (BITSTR); the cin.close (); -          -     } -  +     Private Staticstring getbitstring (String str) { -  +         intLen = 0; A         intbit = 0; at         intnum = 0; -StringBuilder SB =NewStringBuilder (); -          -string[] Strarray = Str.split (""); -Len =strarray.length; -          in         if(Len >= 1024) -         { to             return""; +         } -          the          for(inti = 0; i < Len; i++) *         { $num =Integer.parseint (Strarray[i]);Panax NotoginsengNum/= 4; -bit = num% 2; the  +Sb.append (bit+ ""); A         } the          +         returnSb.tostring (). substring (0, Sb.length ()-1); -     } $      $}

Huawei on-Machine test problem (digital string to binary-java)

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.