360笔试题交流
病毒问题:
package com.bingdu;
import java.util.Scanner;
import java.lang.*;
public class Test1 {
public static int getNum(int n){
int result=0;
int bitpos=0;
int temp=n;
if(n==0)
return 0;
if(n==1)
return 1;
while(temp>=10){
temp/=10;
bitpos++;
}
if(temp>1){
return (int) Math.pow(2,bitpos+1)-1;
}else{
return
(int)Math.pow(2,bitpos)+getNum((int)(n-Math.pow(10,bitpos)));
}
}
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
while(in.hasNext()){
int n=in.nextInt();
System.out.print(getNum(n));
}
in.close();
}
}