Blue Bridge Cup 2020 11th C language group B provincial exercise problem solution-exercise A. Doorplate making

Daily Questions (94)

The 11th Lanqiao Cup C Language Group B Provincial Competition Exercise A: Doorplate Making (5')

Insert picture description here
This question is very simple

C++ code:

#include<iostream>
using namespace std;

int main()
{
    
    
	int sum = 0;
	int m;
	for(int i = 1; i <= 2020; i++)
	{
    
    
		m = i;
		while(m)
		{
    
    
			if(m % 10 == 2)
			{
    
    
				sum++;
			}
			m /= 10;
		}
	}
	cout << sum << endl;
	return 0;
}

Operation result:
Insert picture description here
So the answer is:
624

If you like my article, please remember three consecutive times, like and follow the collection, every like and every one of your attention and every collection will be my infinite motivation on the way forward! ! ! ↖(▔▽▔)↗Thank you for your support, the next issue will be more exciting! ! !

Guess you like

Origin blog.csdn.net/qq_44631615/article/details/113802791