import java.util.Scanner;
public class TestWeng {
public static void main(String[] args) {
// TODO 自動生成的方法存根
/* 對數字求特征值是常用的編碼算法,奇偶特征是一種簡單的特征值。
對于一個整數,從個位開始對每一位數字編号,個位是1号,
十位是2号,以此類推。這個整數在第n位上的數字記作x,
如果x和n的奇偶性相同,則記下一個1,否則記下一個0。
按照整數的順序把對應位的表示奇偶性的0和1都記錄下來,
654321 654321
就形成了一個二進制數字。比如,對于342315, 342315 562123
這個二進制數字就是001101。*/ // 001101 001111
/* 你的程式要讀入一個非負整數,整數的範圍是[0,100000],
然後按照上述算法計算出表示奇偶性的那個二進制數字,
輸出它對應的十進制值。*/
/*輸入格式:
一個非負整數,整數的範圍是[0,1000000]。
輸出格式:
一個整數,表示計算結果。
輸入樣例:
342315
輸出樣例:
13*/
// 奇偶性相同的兩個數的和一定是偶數
// 奇偶性不同的兩個數的和一定是奇數
Scanner in = new Scanner(System.in);
// byte a = 0b1010;
// System.out.println(a);
int input = in.nextInt();
int count = 0;
int a = 0;
int b = 0;
int all = 0;
int all10 = 0;
int i = 0;
int no = 0;
int allAll = 0;
// String twoT = Integer.toBinaryString(two);
// String a = (Integer.toBinaryString(two));
if(input>=0&&input<=1000000){
do
{
i = input%10;
count += 1;
input = input/10;
if((i%2)!=0&&(count%2)!=0
||(i%2)==0&&(count%2)==0)
{
a = count;
}else
{
b = count;
}
if(a>b)
{
all += (int)Math.pow(2,(a-1));
all10 += (int)Math.pow(10,(a-1));
}
// all10 += (int)Math.pow(10,(a-1));
// all10 = (int) (all10+Math.pow(10,(a-1)));
//// all__ =
// System.out.println("all10"+all10);
// no += (int) (Math.pow(10,(b-1)));
// allAll = all10-no;
// System.out.println("allAll:"+allAll);
// System.out.println("no"+no);
// System.out.println("成立a:"+a+" "+"不成立b"+b);
// System.out.println("input"+input);
// System.out.println((int)(i%2)+" --- "+(int)(count%2));
// System.out.println("z1:"+two+" "+"count"+count);
// System.out.println("twoT"+twoT);
}while(input!=0);
// System.out.print("twoT"+twoT);
}
// System.out.println(a+"--"+b);
//把數值all轉換為10進制 現有位數規則count.
System.out.println("十進制"+all);
System.out.println("二進制"+all10);
}
}
public class O {
public static void main(String[] args) {
// TODO 自動生成的方法存根
int sum = 0;
int number = 999;
int c;
int a;
int b = 0;
int sum1 =0;
if (number>=0&&number<=1000000) {
do {
// c=number/10;
a=number%10;
b=b+1; // 第幾位
if(a%2==b%2){
sum=(int) (sum+Math.pow(2, b-1));
sum1=(int) (sum1+Math.pow(10, b-1));
}
number=number/10;
} while (number!=0);
}
System.out.println("十進制"+sum);
System.out.println("二進制"+sum1);
}
}
import java.util.Scanner;
public class Main {
public static void main(String []args) {
Scanner in = new Scanner(System.in);
int x=in.nextInt(),i=0,sum=0;
do {
if(((x%10)+i+1)%2==0)sum+=Math.pow(2,i); //
x=x/10;
i++;
}while(x>0);
System.out.print(sum);
}
}
将程式設計看作是一門藝術,而不單單是個技術。
敲打的英文字元是我的黑白琴鍵,
思維圖紙畫出的是我編寫的五線譜。
當美妙的華章響起,現實通往二進制的大門即将被打開。