Skip to main content

Lucky Four | LUCKFOUR

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

Popular posts from this blog

Find Remainder | FLOW002

Problem Write a program to find the remainder when an integer  A  is divided by an integer  B . Input The first line contains an integer  T , the total number of test cases. Then  T  lines follow, each line contains two Integers  A  and  B . Output For each test case, find the remainder when  A  is divided by  B , and display it in a new line. Constraints 1  ≤   T   ≤  1000 1  ≤   A,B   ≤  10000 Sample 1: Input Output 3 1 2 100 200 40 15 1 100 10 Solution: #include<iostream> using namespace std; int main(){     int t;     cin>>t;     while(t--){         int a, b;         cin>>a>>b;         cout<<a%b<<endl;     }     return 0; }

Id and Ship | FLOW010

Problem Write a program that takes in a letterclass ID of a ship and display the equivalent string class description of the given ID. Use the table below. Class ID Ship Class B or b BattleShip C or c Cruiser D or d Destroyer F or f Frigate Input Format The first line contains an integer  T , the total number of testcases. Then  T  lines follow, each line contains a character. Output Format For each test case, display the Ship Class depending on ID, in a new line. Constraints 1  ≤   T   ≤  1000 Sample 1: Input Output 3 B c D BattleShip Cruiser  Destroyer   Solution: #include <iostream> using namespace std; int main() { // your code goes here int t; char ch; cin>>t; while(t--) { cin>>ch; if(ch=='B' || ch=='b') cout<<"BattleShip"<<endl; if(ch=='C' || ch=='c') cout<<"Cruiser"<<endl; if(ch=='D' || ch=='d') cout<<"Destroyer"<...

Valid Triangles | FLOW013

  Problem Write a program to check whether a triangle is valid or not, when the three angles of the triangle are the inputs. A triangle is valid if the sum of all the three angles is equal to 180 degrees. Input Format The first line contains an integer  T , the total number of testcases. Then  T  lines follow, each line contains three angles  A ,  B  and  C , of the triangle separated by space. Output Format For each test case, display 'YES' if the triangle is valid, and 'NO', if it is not, in a new line. Constraints 1  ≤   T   ≤  1000 1  ≤   A,B,C   ≤  180 Sample 1: Input Output 3 40 40 100 45 45 90 180 1 1 YES YES NO Solution: #include <iostream> using namespace std; int main() { // your code goes here int t; cin>>t; while(t--){     int a,b,c;     cin>>a>>b>>c;     if((a+b+c)==180)         cout<<"YES"; ...