Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main{
  3.  
  4. public static void main(String []args){
  5. Scanner in = new Scanner(System.in);
  6. int num = in.nextInt();
  7. int count = 0;
  8. int x = num;
  9.  
  10. String temp = Integer.toString(num);
  11. for(int i = 0;i<temp.length();i++){
  12. if (x % 10 == 2) {
  13. count++;
  14.  
  15. }
  16. x = x / 10;
  17. }
  18.  
  19. int len = temp.length();
  20. double [] list = new double[len];
  21. double y = Math.floor(num / (Math.pow(10,(len-1))));
  22. list[len-1] = y;
  23. double answer = 0;
  24.  
  25. while(len >= 1){
  26. if(y > 2) {
  27. answer += (1 * Math.pow(10, len - 1));
  28. }
  29. if(y >= 2 || list[len-1] != 2 ) {
  30. answer += ((y) * ((len - 1) * (Math.pow(10, len - 2))));
  31. }
  32. if(list[len-1] == 2){
  33. answer += num % Math.pow(10,len-1);
  34. }
  35. len --;
  36. y = Math.floor((num / (Math.pow(10,(len-1))) % 10));
  37. if(len != 0) {
  38. list[len - 1] = y;
  39. }
  40. }
  41.  
  42. answer += count;
  43. System.out.println(answer);
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement