LUCKFOUR - editorial

import java.util.;
import java.lang.
;
import java.io.*;

class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
        Scanner sc = new Scanner(System.in);
        int t = sc.hasNextInt()?sc.nextInt():0;
        for(int i=0;i<t;i++){
            String s = sc.hasNext()?sc.next():"";
            int count= 0;
            for(int j = 0;j<s.length();j++){
                count= s.charAt(j)=='4'?count+1:count;
            }
            System.out.println(count);
    	}
	}
}

my code worked in python 2.7.13
check out this code for your reference:

x=int(input())
for i in range(x):
n=int(input())
count=0
while(n>0):
res=n%10
if(res==4):
count=count+1
n=n/10
print(count)

I don’t understand what I’ve to do under Subtasks 1 and 2. Can someone help me out? I have identified the frequency of 4s present in my numeral and that part works perfectly

link to solution
Lucky Four CodeChef LUCKFOUR - YouTube

its not working

bro i dont understand ur logic explain plz

I used string instead of integer in each test case

#include <bits/stdc++.h>
using namespace std;

int main()
{
int t;
cin>>t;
cin.ignore();
while(t–){
string s;
cin>>s;
int count=0;
for (int i = 0; i < s.size(); ++i)
{
if ((s[i]-‘0’)==4)
{
count=count+1;
}
}

	cout<<count<<endl;

}

}

Okay so what I did is I took the input of each test case as string and ran a for loop from 0 to length of the string -1 and compared each of the index of string string with 4 whenever I found 4 I increased the count and finally printed the count