Lucky Four

 Lucky Four

Problem Description


Kostya likes the number 4 much. Of course! This number has such a lot of properties, like:


1. Four is the smallest composite number;

2. It is also the smallest Smith number;

3. The smallest non-cyclic group has four elements;

4. Four is the maximal degree of the equation that can be solved in radicals;

5. There is four-color theorem that states that any map can be colored in no more than four colors in such a way that no two adjacent regions are colored in the same color;

6. Lagrange's four-square theorem states that every positive integer can be written as the sum of at most four square numbers;

7. Four is the maximum number of dimensions of a real division algebra;

8. In bases 6 and 12, 4 is a 1-automorphic number;


And there are a lot more cool stuff about this number! impressed by the power of this number, Kostya has begun to look for occurrences of four anywhere. He has a list of T integers, for each of them he wants to calculate the number of occurrences of the digit 4 in the decimal representation. He is too busy now, so please help him.


The first line of input consists of a single integer T, denoting the number of integers in Kostya's list.

Then, there are T lines, each of them contain a single integer from the list

Output T lines. Each of these lines should contain the number of occurences of the digit 4 in the respective integer from Kostya's list.


Constraints

1<=T <=105

(Subtask 1): 0 Numbers from the list 9 - 33 points.

(Subtask 2): 0 Numbers from the list 109 - 67 points.

Logic Test Case 1


Input (stdin)

5


447474


228


6664


40


81


Expected Output


4


0


1


1


0

Logic Test Case 2


Input (stdin)

5


1234


31


345


2442


23


Expected Output


1


0


1


2


0





Coding Area

import java.io.*;
import java.util.Scanner;
public class TestClass {
public static void main(String[] args)
     { 
       Scanner s=new Scanner(System.in);
       int n=s.nextInt();
       for(int i=0;i<n;i++)
       { 
         int t=s.nextInt();
         int k=t;
         int count=0;
         while(k>0)
         { 
           int rem=k%10;
           if(rem==4)
           { 
             count++;
           } 
           k=k/10;
         } 
         System.out.println(count);
         }
}
}

Post a comment

0 Comments