Problem
Read problem statements in Mandarin Chinese and Russian.
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.
Sample 1:
Input
Output
5
447474
228
6664
40
81
4
0
1
1
0
Explanation:
There are four 4s in the 447474, no 4s in 228, one 4s in 6664
Solution:
#include <iostream>
using namespace std;
int main() {
// your code goes here
int t;
cin >> t;
while(t--){
int i;
cin >> i;
int count=0;
for(int j=i;j>0;){
if(j%10==4){
count=count+1;
}
j=j/10;
}
cout << count<< endl;
}
return 0;
}
Comments
Post a Comment