Algorithm


problem Link : https://www.codechef.com/problems/LUCKYFR

Problem

Karan likes the number 4 very much.

Impressed by the power of this number, Karan 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.

Input Format

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

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

Output Format

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

Constraints

  • 1 ≤ T ≤ 10^5
  • (Subtask 1): 0 ≤ Numbers from the list ≤ 9 - 33 points.
  • (Subtask 2): 0 ≤ Numbers from the list ≤ 109 - 67 points.

Sample 1:

Input
 
Output
 
5
447474
228
6664
40
81
4
0
1
1
0

Code Examples

#1 Code Example with C Programming

Code - C Programming

#include<stdio.h>
int main()
{
    int t,num;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&num);
        int count=0;
        while(num!=0)
        {
            if(num%10==4) count++;
            num/=10;
        }
        printf("%d\n",count);
    }
} 
Copy The Code & Try With Live Editor

Input

x
+
cmd
5
447474
228
6664
40
81

Output

x
+
cmd
4
0
1
1 0
Advertisements

Demonstration


CodeChef solution LUCKFOUR  - Lucky Four Codechef solution in Codechef solution in C,C++

Previous
CodeChef solution CHOPRT - Chef And Operators Codechef solution in C,C++
Next
CodeChef solution WORDLE - Wordle Codechef solution in C,C++