Lucky Four solution in C language - Codechef

   

Lucky Four

Problem Code: LUCKFOUR

You are given a list of T integers, for each of them you have to calculate the number of occurrences of the digit 4 in the decimal representation.

Input

The first line of input consists of a single integer T, denoting the number of integers in the list.
Then, there are T lines, each of them contain a single integer from the list.

Output

Output T lines. Each of these lines should contain the number of occurrences of the digit 4 in the respective integer from the 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.

Example - Incorrect Withdrawal Amount (not multiple of 5)

Input:
5
447474
228
6664
40
81

Output:
4
0
1
1
0


. . .

Solution in C.


#include <stdio.h>
int main(void) {
    int t;
    scanf("%d",&t);
    while(t--){
        int a, count=0;
        scanf("%d",&a);
        while(a>0){
            int b = a%10;
            if(b==4){
                count++;
            }
            a = a/10;
        }
        printf("%d\n",count);
    }
    return 0;
}


Comments

Popular posts from this blog

ATM solution in C language.- Codechef

MOTIVATION SOLUTION IN C LANGUAGE | CODECHEF | IMDB

APPLE AND ORANGE | HACKERRANK | PROBLEM SOLVING | SOLUTION IN C