Numeric feature value,

Source: Internet
Author: User

Numeric feature value,

Subject content:

The feature value of a number is a common encoding algorithm, and the parity feature is a simple feature value. For an integer, each digit is numbered from a single digit, one digit is numbered 1, ten digits are numbered 2, and so on. The number of the nth digit is counted as x. If x and n have the same parity, 1 is recorded; otherwise, 0 is recorded. In the order of integers, the values 0 and 1 representing parity are recorded to form a binary number. For example, for 342315, this binary number is 001101.

 

The calculation here can be expressed in the following table:

Number

3

4

2

3

1

5

Digit

6

5

4

3

2

1

Digit parity

Odd

Even

Even

Odd

Odd

Odd

Digit parity

Even

Odd

Even

Odd

Even

Odd

Parity

0

0

1

1

0

1

Binary Value

32

16

8

4

2

1

 

Result 13 is displayed when the bitwise value of 1 is added to the binary value.

 

Your program needs to read a non-negative integer in the range of [0,], and then calculate the binary number representing parity according to the above algorithm, and output its corresponding decimal value.

 

Tip: the integer is decomposed from the right to the left. Each digit is incremented by 1, while the binary value is multiplied by 2.

 

Input Format:

A non-negative integer in the range of [0,].

 

Output Format:

An integer that indicates the calculation result.

 

Input example:

342315

 

Output example:

13

 

 

Import java. util. collections;

Public class Main {
Public static void main (String [] args ){
Int number = 0; // read a non-negative integer
Int digit = 0; // Decomposition
Int wei = 0; // Digit
Int sum = 0; // Calculation Result
Running in = new Processing (System. in );

Number = in. nextInt ();

Do {
Digit = number % 10;
Number/= 10;
Wei ++;

If (digit % 2) = (wei % 2 )){
Sum + = Math. pow (2, (wei-1 ));
}
} While (number> 0); // splits integers from the right to the left. Each digit is incremented by 1, while the binary value is multiplied by 2.

System. out. println (sum );
}
}

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.