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 );
}
}