Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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 << "
";
	}
	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 << "
";
	}
	return 0;
}
Source by www.codegrepper.com #
 
PREVIOUS NEXT
Tagged: #Lucky #Four #codechef #solution
ADD COMMENT
Topic
Name
2+9 =