第二期训练题白银组:01

原题地址
在这里插入图片描述
问题简述:4和7为幸运数字,只含有4和7的数是幸运数。输入一个数,这个数含有4和7的数量为X,判断X是不是幸运数。
思路:先统计4,7的数量,再判断X。
ac的c++代码如下:

#include <iostream>
using namespace std;
int main()
{
	long long unsigned int a;
	cin >> a;
	int j = 0;
	for (int i = 0;a!=0; i++)
	{
		int c = a % 10;
		if (c == 4 || c == 7)
			j++;
		a = a - c;
		a = a/ 10;
	}
	int g = 0;
	if (j == 0)
		cout << "NO";
	else
	{
		for (int i = 0; j != 0; i++)
		{
			int d = j % 10;
			if (d != 4 && d != 7)
			{
				g++;
			}
			j = j - d;
			j = j / 10;
		}
		if (g == 0)
			cout << "YES";
		else
			cout << "NO";
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/Go_Joe/article/details/84961126