Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main{
- public static void main(String []args){
- Scanner in = new Scanner(System.in);
- int num = in.nextInt();
- int count = 0;
- int x = num;
- String temp = Integer.toString(num);
- for(int i = 0;i<temp.length();i++){
- if (x % 10 == 2) {
- count++;
- }
- x = x / 10;
- }
- int len = temp.length();
- double [] list = new double[len];
- double y = Math.floor(num / (Math.pow(10,(len-1))));
- list[len-1] = y;
- double answer = 0;
- while(len >= 1){
- if(y > 2) {
- answer += (1 * Math.pow(10, len - 1));
- }
- if(y >= 2 || list[len-1] != 2 ) {
- answer += ((y) * ((len - 1) * (Math.pow(10, len - 2))));
- }
- if(list[len-1] == 2){
- answer += num % Math.pow(10,len-1);
- }
- len --;
- y = Math.floor((num / (Math.pow(10,(len-1))) % 10));
- if(len != 0) {
- list[len - 1] = y;
- }
- }
- answer += count;
- System.out.println(answer);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement