Horje
Lucky Four codechef solution in c++ Code Example
Lucky Four codechef solution in c++
------------------------------------------------------------------------------------------
//solution<1>:
------------------------------------------------------------------------------------------
#include<iostream>
#include<string>
using namespace std;

int main()
{
	int t, n, count;
	cin >> t;
	for (int i = 0; i < t; i++)
	{
		cin >> n;
		string s = to_string(n);
		count = 0;
		for (int i = 0; i < s.length(); i++)
		{
			if (s[i] == '4')
				count++;
		}
		cout << count << "\n";
	}
	return 0;
}
------------------------------------------------------------------------------------------
//solution<2>:
------------------------------------------------------------------------------------------
#include<iostream>
using namespace std;

int main()
{
	int t, n, count, x;
	cin >> t;
	for (int i = 0; i < t; i++)
	{
		cin >> n;
		count = 0;
		while(n!=0)
		{
			x = n % 10;
			if (x == 4)
			{
				count++;
			}
			n /= 10;
		}
		cout << count << "\n";
	}
	return 0;
}
Lucky four codechef solution
t=int(input())
a=str(4)
for i in range(t):
  x=str(input())
  count=0
  for j in x:
    if j==a:
      count=count+1
   print(count)




Cpp

Related
c++ abs template Code Example c++ abs template Code Example
c++ program to print natural numbers from 1 to 10 in reverse order using while loop Code Example c++ program to print natural numbers from 1 to 10 in reverse order using while loop Code Example
remove element from c++ Code Example remove element from c++ Code Example
Corong_ExerciseNo3(2) Code Example Corong_ExerciseNo3(2) Code Example
(1 & 1) in cpp Code Example (1 & 1) in cpp Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
13